| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085 |
- <?php
- namespace app\routine\controller;
- use Api\Express;
- use app\routine\model\routine\RoutineCode;
- use app\routine\model\routine\RoutineFormId;
- use app\routine\model\routine\RoutineTemplate;
- use app\routine\model\store\StoreCombination;
- use service\JsonService;
- use service\GroupDataService;
- use service\MiniProgramService;
- use service\RoutineBizDataCrypt;
- use service\SystemConfigService;
- use service\UploadService;
- use service\UtilService;
- use think\Request;
- use service\WechatTemplateService;
- use service\CacheService;
- use service\HookService;
- use behavior\StoreProductBehavior;
- use think\Url;
- use app\routine\model\store\StoreCouponUser;
- use app\routine\model\store\StoreOrder;
- use app\routine\model\store\StoreProductRelation;
- use app\routine\model\store\StoreProductAttr;
- use app\routine\model\store\StoreProductAttrValue;
- use app\routine\model\store\StoreProductReply;
- use app\routine\model\store\StoreCart;
- use app\routine\model\store\StoreCategory;
- use app\routine\model\store\StoreProduct;
- use app\routine\model\store\StoreSeckill;
- use app\routine\model\user\User;
- use app\routine\model\user\UserNotice;
- use app\routine\model\store\StoreCouponIssue;
- use app\routine\model\store\StoreCouponIssueUser;
- use app\routine\model\store\StoreOrderCartInfo;
- use app\routine\model\store\StorePink;
- use app\routine\model\store\StoreService;
- use app\routine\model\store\StoreServiceLog;
- use app\routine\model\user\UserAddress;
- use app\routine\model\user\UserBill;
- use app\routine\model\user\UserExtract;
- use app\routine\model\user\UserRecharge;
- use app\routine\model\user\UserSign;
- use app\routine\model\user\WechatUser;
- use app\admin\model\system\SystemConfig;
- use app\routine\model\store\StoreBargain;
- use app\routine\model\store\StoreBargainUser;
- use app\routine\model\store\StoreBargainUserHelp;
- use app\routine\model\article\Article as ArticleModel;
- /**
- * 小程序接口
- * Class AuthApi
- * @package app\routine\controller
- *
- */
- class AuthApi extends AuthController{
- /**
- * 获取用户信息
- * @return \think\response\Json
- */
- // public function get_user_info(){
- // return JsonService::successful($this->userInfo);
- // }
- /**
- * 获取退款理由
- */
- public function get_refund_reason(){
- $reason = SystemConfig::getValue('stor_reason')?:[];//退款理由
- $reason = str_replace("\r\n","\n",$reason);//防止不兼容
- $reason = explode("\n",$reason);
- return JsonService::successful($reason);
- }
- /**
- * 获取提现银行
- */
- public function get_user_extract_bank(){
- $extractBank = SystemConfig::getValue('user_extract_bank')?:[];//提现银行
- $extractBank = str_replace("\r\n","\n",$extractBank);//防止不兼容
- $extractBank = explode("\n",$extractBank);
- return JsonService::successful($extractBank);
- }
- /**
- * 首页
- */
- public function index(){
- $banner = GroupDataService::getData('routine_home_banner')?:[];//banner图
- $menus = GroupDataService::getData('routine_home_menus')?:[];//banner图
- $lovely = GroupDataService::getData('routine_lovely')?:[];//猜你喜欢图
- $best = StoreProduct::getBestProduct('id,image,store_name,cate_id,price,unit_name,sort',8);//精品推荐
- $new = StoreProduct::getNewProduct('id,image,store_name,cate_id,price,unit_name,sort',3);//首发
- $hot = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,unit_name,sort',8);//热卖
- $benefit = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name,sort',3);//促销
- $like = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,unit_name,sort',6);//猜你喜欢
- $data['banner'] = $banner;
- $data['lovely'] = $lovely[0];
- $data['menus'] = $menus;
- $data['best'] = $best;
- $data['new'] = $new;
- $data['hot'] = $hot;
- $data['benefit'] = $benefit;
- $data['like'] = $like;
- return JsonService::successful($data);
- }
- /**
- * 猜你喜欢 加载
- * @param Request $request
- */
- public function get_hot_product(Request $request){
- $data = UtilService::postMore([['offset',0],['limit',0]],$request);
- $hot = StoreProduct::getHotProductLoading('id,image,store_name,cate_id,price,unit_name,sort',$data['offset'],$data['limit']);//猜你喜欢
- return JsonService::successful($hot);
- }
- /**
- * 分类搜索页面
- * @param Request $request
- * @return \think\response\Json
- */
- public function store(){
- $model = StoreProduct::validWhere();
- if($_GET){$data = $_GET['value'];
- if($data!=''){
- $model = $model->where('store_name','LIKE',"%$data%")->whereOr('keyword','LIKE',"%$data%");
- if((int)$data) $model = $model->whereOr('id',$data);
- }
- $list = $model->field('id,store_name,cate_id,image,sales,price,stock')->select()->toArray();
- return JsonService::successful($list);
- }
- }
- /**
- * 分类页面
- * @param Request $request
- * @return \think\response\Json
- */
- public function store1(Request $request){
- $data = UtilService::postMore([['keyword',''],['cid',''],['sid','']],$request);
- $keyword = addslashes($data['keyword']);
- $cid = intval($data['cid']);
- $sid = intval($data['sid']);
- $category = null;
- if($sid) $category = StoreCategory::get($sid);
- if($cid && !$category) $category = StoreCategory::get($cid);
- $data['keyword'] = $keyword;
- $data['cid'] = $cid;
- $data['sid'] = $sid;
- return JsonService::successful($data);
- }
- /**
- * 一级分类
- * @return \think\response\Json
- */
- public function get_pid_cate(){
- $data = StoreCategory::pidByCategory(0,'id,cate_name');//一级分类
- return JsonService::successful($data);
- }
- /**
- * 最小提现金额
- * @return \think\response\Json
- */
- public function minmoney(){
- $data = SystemConfig::getValue('user_extract_min_price');//最小提现金额
- return JsonService::successful($data);
- }
- /**
- * 二级分类
- * @param Request $request
- * @return \think\response\Json
- */
- public function get_id_cate(Request $request){
- $data = UtilService::postMore([['id',0]],$request);
- $dataCateA = [];
- $dataCateA[0]['id'] = $data['id'];
- $dataCateA[0]['cate_name'] = '全部商品';
- $dataCateA[0]['pid'] = 0;
- $dataCateE = StoreCategory::pidBySidList($data['id']);//根据一级分类获取二级分类
- if($dataCateE) $dataCateE = $dataCateE->toArray();
- $dataCate = [];
- $dataCate = array_merge_recursive($dataCateA,$dataCateE);
- return JsonService::successful($dataCate);
- }
- /**
- * 分类页面产品
- * @param string $keyword
- * @param int $cId
- * @param int $sId
- * @param string $priceOrder
- * @param string $salesOrder
- * @param int $news
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_product_list(Request $request)
- {
- $data = UtilService::getMore([
- ['sid',0],
- ['cid',0],
- ['keyword',''],
- ['priceOrder',''],
- ['salesOrder',''],
- ['news',0],
- ['first',0],
- ['limit',0]
- ],$request);
- $sId = $data['sid'];
- $cId = $data['cid'];
- $keyword = $data['keyword'];
- $priceOrder = $data['priceOrder'];
- $salesOrder = $data['salesOrder'];
- $news = $data['news'];
- $first = $data['first'];
- $limit = $data['limit'];
- $model = StoreProduct::validWhere();
- if($sId){
- $model->where('cate_id',$sId);
- }elseif($cId){
- $sids = StoreCategory::pidBySidList($cId)?:[];
- if($sids){
- $sidsr = [];
- foreach($sids as $v){
- $sidsr[] = $v['id'];
- }
- $model->where('cate_id','IN',$sidsr);
- }
- }
- if(!empty($keyword)) $model->where('keyword|store_name','LIKE',htmlspecialchars("%$keyword%"));
- if($news!=0) $model->where('is_new',1);
- $baseOrder = '';
- if($priceOrder) $baseOrder = $priceOrder == 'desc' ? 'price DESC' : 'price ASC';
- // if($salesOrder) $baseOrder = $salesOrder == 'desc' ? 'sales DESC' : 'sales ASC';//真实销量
- if($salesOrder) $baseOrder = $salesOrder == 'desc' ? 'ficti DESC' : 'ficti ASC';//虚拟销量
- if($baseOrder) $baseOrder .= ', ';
- $model->order($baseOrder.'sort DESC, add_time DESC');
- $list = $model->limit($first,$limit)->field('id,store_name,cate_id,image,sales,ficti,price,stock')->select()->toArray();
- return JsonService::successful($list);
- }
- /**
- * 购物车
- * @return \think\response\Json
- */
- public function get_cart_list(){
- return JsonService::successful(StoreCart::getUserProductCartList($this->userInfo['uid']));
- }
- /**
- * 商品详情页
- * @param Request $request
- */
- public function details(Request $request){
- $data = UtilService::postMore(['id'],$request);
- $id = $data['id'];
- if(!$id || !($storeInfo = StoreProduct::getValidProduct($id))) return JsonService::fail('商品不存在或已下架');
- $storeInfo['userCollect'] = StoreProductRelation::isProductRelation($id,$this->userInfo['uid'],'collect');
- list($productAttr,$productValue) = StoreProductAttr::getProductAttrDetail($id);
- setView($this->userInfo['uid'],$id,$storeInfo['cate_id'],'viwe');
- foreach ($productAttr as $k=>$v){
- $attr = $v['attr_values'];
- // unset($productAttr[$k]['attr_values']);
- foreach ($attr as $kk=>$vv){
- $productAttr[$k]['attr_value'][$kk]['attr'] = $vv;
- $productAttr[$k]['attr_value'][$kk]['check'] = false;
- }
- }
- $data['storeInfo'] = $storeInfo;
- $data['similarity'] = StoreProduct::cateIdBySimilarityProduct($storeInfo['cate_id'],'id,store_name,image,price,sales,ficti',4);
- $data['productAttr'] = $productAttr;
- $data['productValue'] = $productValue;
- $data['reply'] = StoreProductReply::getRecProductReply($storeInfo['id']);
- $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id',$storeInfo['id'])->count();
- $data['mer_id'] = StoreProduct::where('id',$storeInfo['id'])->value('mer_id');
- return JsonService::successful($data);
- }
- /**
- * 获取产品评论
- * @param int $productId
- * @return \think\response\Json
- */
- public function get_product_reply($productId = 0){
- if(!$productId) return JsonService::fail('参数错误');
- $replyCount = StoreProductReply::productValidWhere()->where('product_id',$productId)->count();
- $reply = StoreProductReply::getRecProductReply($productId);
- return JsonService::successful(['replyCount'=>$replyCount,'reply'=>$reply]);
- }
- /**
- * 订单页面
- * @param Request $request
- * @return \think\response\Json
- */
- public function confirm_order(Request $request){
- $data = UtilService::postMore(['cartId'],$request);
- $cartId = $data['cartId'];
- if(!is_string($cartId) || !$cartId ) return JsonService::fail('请提交购买的商品');
- $cartGroup = StoreCart::getUserProductCartList($this->userInfo['uid'],$cartId,1);
- if(count($cartGroup['invalid'])) return JsonService::fail($cartGroup['invalid'][0]['productInfo']['store_name'].'已失效!');
- if(!$cartGroup['valid']) return JsonService::fail('请提交购买的商品');
- $cartInfo = $cartGroup['valid'];
- $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo);
- $other = [
- 'offlinePostage'=>SystemConfigService::get('offline_postage'),
- 'integralRatio'=>SystemConfigService::get('integral_ratio')
- ];
- $usableCoupon = StoreCouponUser::beUsableCoupon($this->userInfo['uid'],$priceGroup['totalPrice']);
- $cartIdA = explode(',',$cartId);
- if(count($cartIdA) > 1) $seckill_id=0;
- else{
- $seckillinfo = StoreCart::where('id',$cartId)->find();
- if((int)$seckillinfo['seckill_id']>0) $seckill_id=$seckillinfo['seckill_id'];
- else $seckill_id=0;
- }
- $data['usableCoupon'] = $usableCoupon;
- $data['seckill_id'] = $seckill_id;
- $data['cartInfo'] = $cartInfo;
- $data['priceGroup'] = $priceGroup;
- $data['orderKey'] = StoreOrder::cacheOrderInfo($this->userInfo['uid'],$cartInfo,$priceGroup,$other);
- $data['offlinePostage'] = $other['offlinePostage'];
- $data['userInfo'] = User::getUserInfo($this->userInfo['uid']);
- $data['integralRatio'] = $other['integralRatio'];
- return JsonService::successful($data);
- }
- /**
- * 获取可以使用的优惠券
- * @param int $totalPrice
- * @return \think\response\Json
- */
- public function get_use_coupon_order($totalPrice = 0){
- return JsonService::successful(StoreCouponUser::beUsableCouponList($this->userInfo['uid'],$totalPrice));
- }
- /**
- * 秒杀列表页
- * @return \think\response\Json
- */
- public function seckill_index(){
- $lovely = GroupDataService::getData('routine_lovely')?:[];//banner图
- $seckill = StoreSeckill::where('is_del',0)->where('status',1)->where('start_time','<',time())->where('stop_time','>',time())->order('sort desc')->select()->toArray();
- $data['seckill'] = $seckill;
- $data['lovely'] = $lovely[1];
- return JsonService::successful($data);
- }
- /**
- * 秒杀详情页
- * @param Request $request
- * @return \think\response\Json
- */
- public function seckill_detail(Request $request){
- $data = UtilService::postMore(['id'],$request);
- $id = $data['id'];
- if(!$id || !($storeInfo = StoreSeckill::getValidProduct($id))) return JsonService::fail('商品不存在或已下架!');
- $storeInfo['userLike'] = StoreProductRelation::isProductRelation($storeInfo['product_id'],$this->userInfo['uid'],'like','product_seckill');
- $storeInfo['like_num'] = StoreProductRelation::productRelationNum($storeInfo['product_id'],'like','product_seckill');
- $storeInfo['userCollect'] = StoreProductRelation::isProductRelation($storeInfo['product_id'],$this->userInfo['uid'],'collect','product_seckill');
- $data['storeInfo'] = $storeInfo;
- setView($this->userInfo['uid'],$id,$storeInfo['product_id'],'viwe');
- $data['reply'] = StoreProductReply::getRecProductReply($storeInfo['product_id']);
- $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id',$storeInfo['id'])->count();
- return JsonService::successful($data);
- }
- /**
- * 个人中心
- * @return \think\response\Json
- */
- public function my(){
- $this->userInfo['couponCount'] = StoreCouponUser::getUserValidCouponCount($this->userInfo['uid']);
- $this->userInfo['like'] = StoreProductRelation::getUserIdCollect($this->userInfo['uid']);;
- $this->userInfo['orderStatusNum'] = StoreOrder::getOrderStatusNum($this->userInfo['uid']);
- $this->userInfo['notice'] = UserNotice::getNotice($this->userInfo['uid']);
- $this->userInfo['statu'] = (int)SystemConfig::getValue('store_brokerage_statu');
- // $this->userInfo['service_phone'] = SystemConfig::getValue('service_phone');
- // $this->userInfo['service_phone_str'] = SystemConfig::getValue('service_phone_str');
- return JsonService::successful($this->userInfo);
- }
- /**
- * 过度查$uniqueId
- * @param string $productId
- * @param int $cartNum
- * @param string $uniqueId
- * @return \think\response\Json
- */
- public function unique(){
- $productId=$_GET['productId'];
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- $uniqueId=StoreProductAttrValue::where('product_id',$productId)->value('unique');
- $data=$this->set_cart($productId,$cartNum = 1,$uniqueId);
- if($data==true){
- return JsonService::successful('ok');
- }
- }
- /**
- * 加入到购物车
- * @param string $productId
- * @param int $cartNum
- * @param string $uniqueId
- * @return \think\response\Json
- */
- public function set_cart($productId = '',$cartNum = 1,$uniqueId = ''){
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- $res = StoreCart::setCart($this->userInfo['uid'],$productId,$cartNum,$uniqueId,'product');
- if(!$res) return JsonService::fail(StoreCart::getErrorInfo());
- else{
- // HookService::afterListen('store_product_set_cart_after',$res,$this->userInfo,false,StoreProductBehavior::class);
- return JsonService::successful('ok',['cartId'=>$res->id]);
- }
- }
- /**
- * 拼团 秒杀 砍价 加入到购物车
- * @param string $productId
- * @param int $cartNum
- * @param string $uniqueId
- * @param int $combinationId
- * @param int $secKillId
- * @return \think\response\Json
- */
- public function now_buy($productId = '',$cartNum = 1,$uniqueId = '',$combinationId = 0,$secKillId = 0,$bargainId = 0){
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- if($bargainId && StoreBargainUserHelp::getSurplusPrice($bargainId,$this->userInfo['uid'])) return JsonService::fail('请先砍价');
- $res = StoreCart::setCart($this->userInfo['uid'],$productId,$cartNum,$uniqueId,'product',1,$combinationId,$secKillId,$bargainId);
- if(!$res) return JsonService::fail(StoreCart::getErrorInfo());
- else return JsonService::successful('ok',['cartId'=>$res->id]);
- }
- /**
- * 添加点赞
- * @param string $productId
- * @param string $category
- * @return \think\response\Json
- */
- public function like_product($productId = '',$category = 'product'){
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- $res = StoreProductRelation::productRelation($productId,$this->userInfo['uid'],'like',$category);
- if(!$res) return JsonService::fail(StoreProductRelation::getErrorInfo());
- else return JsonService::successful();
- }
- /**
- * 取消点赞
- * @param string $productId
- * @param string $category
- * @return \think\response\Json
- */
- public function unlike_product($productId = '',$category = 'product'){
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- $res = StoreProductRelation::unProductRelation($productId,$this->userInfo['uid'],'like',$category);
- if(!$res) return JsonService::fail(StoreProductRelation::getErrorInfo());
- else return JsonService::successful();
- }
- /**
- * 添加收藏
- * @param $productId
- * @param string $category
- * @return \think\response\Json
- */
- public function collect_product($productId,$category = 'product'){
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- $res = StoreProductRelation::productRelation($productId,$this->userInfo['uid'],'collect',$category);
- if(!$res) return JsonService::fail(StoreProductRelation::getErrorInfo());
- else return JsonService::successful();
- }
- /**
- * 批量收藏
- * @param string $productId
- * @param string $category
- * @return \think\response\Json
- */
- public function collect_product_all($productId = '',$category = 'product'){
- if($productId == '') return JsonService::fail('参数错误');
- $productIdS = explode(',',$productId);
- $res = StoreProductRelation::productRelationAll($productIdS,$this->userInfo['uid'],'collect',$category);
- if(!$res) return JsonService::fail(StoreProductRelation::getErrorInfo());
- else return JsonService::successful();
- }
- /**
- * 取消收藏
- * @param $productId
- * @param string $category
- * @return \think\response\Json
- */
- public function uncollect_product($productId,$category = 'product'){
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- $res = StoreProductRelation::unProductRelation($productId,$this->userInfo['uid'],'collect',$category);
- if(!$res) return JsonService::fail(StoreProductRelation::getErrorInfo());
- else return JsonService::successful();
- }
- /**
- * 获取购物车数量
- * @return \think\response\Json
- */
- public function get_cart_num(){
- return JsonService::successful('ok',StoreCart::getUserCartNum($this->userInfo['uid'],'product'));
- }
- /**
- * 修改购物车产品数量
- * @param string $cartId
- * @param string $cartNum
- * @return \think\response\Json
- */
- public function change_cart_num($cartId = '',$cartNum = ''){
- if(!$cartId || !$cartNum || !is_numeric($cartId) || !is_numeric($cartNum)) return JsonService::fail('参数错误!');
- StoreCart::changeUserCartNum($cartId,$cartNum,$this->userInfo['uid']);
- return JsonService::successful();
- }
- /**
- * 删除购物车产品
- * @param string $ids
- * @return \think\response\Json
- */
- public function remove_cart($ids=''){
- if(!$ids) return JsonService::fail('参数错误!');
- StoreCart::removeUserCart($this->userInfo['uid'],$ids);
- return JsonService::successful();
- }
- /**
- * 获取用户优惠券
- * @return \think\response\Json
- */
- public function get_use_coupons(){
- if($_GET){
- if($_GET['types']==0||$_GET['types']==''){
- $list= StoreCouponUser::getUserAllCoupon($this->userInfo['uid']);
- }elseif($_GET['types']==1){
- $list=StoreCouponUser::getUserValidCoupon($this->userInfo['uid']);
- }elseif($_GET['types']==2){
- $list=StoreCouponUser::getUserAlreadyUsedCoupon($this->userInfo['uid']);
- }else{
- $list=StoreCouponUser::getUserBeOverdueCoupon($this->userInfo['uid']);
- }
- foreach ($list as &$v){
- $v['add_time'] = date('Y/m/d',$v['add_time']);
- $v['end_time'] = date('Y/m/d',$v['end_time']);
- }
- return JsonService::successful($list);
- }
- }
- /**
- * 获取用户优惠券
- * @return \think\response\Json
- */
- public function get_use_coupon(){
- return JsonService::successful('',StoreCouponUser::getUserAllCoupon($this->userInfo['uid']));
- }
- /**
- * 获取收藏产品
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_user_collect_product($first = 0,$limit = 8)
- {
- $list = StoreProductRelation::where('A.uid',$this->userInfo['uid'])
- ->field('B.id pid,B.store_name,B.price,B.ot_price,B.sales,B.image,B.is_del,B.is_show')->alias('A')
- ->where('A.type','collect')->where('A.category','product')
- ->order('A.add_time DESC')->join('__STORE_PRODUCT__ B','A.product_id = B.id')
- ->limit($first,$limit)->select()->toArray();
- foreach ($list as $k=>$product){
- if($product['pid']){
- $list[$k]['is_fail'] = $product['is_del'] && $product['is_show'];
- }else{
- unset($list[$k]);
- }
- }
- return JsonService::successful($list);
- }
- /**
- * 获取收藏产品删除
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_user_collect_product_del()
- {
- if($_GET){
- $list = StoreProductRelation::where('uid',$this->userInfo['uid'])->where('product_id',$_GET['pid'])->delete();
- return JsonService::successful($list);
- }
- }
- /**
- * 设置为默认地址
- * @param string $addressId
- * @return \think\response\Json
- */
- public function set_user_default_address($addressId = '')
- {
- if(!$addressId || !is_numeric($addressId)) return JsonService::fail('参数错误!');
- if(!UserAddress::be(['is_del'=>0,'id'=>$addressId,'uid'=>$this->userInfo['uid']]))
- return JsonService::fail('地址不存在!');
- $res = UserAddress::setDefaultAddress($addressId,$this->userInfo['uid']);
- if(!$res)
- return JsonService::fail('地址不存在!');
- else
- return JsonService::successful();
- }
- /**
- * 修改收货地址
- * @return \think\response\Json
- */
- public function edit_user_address()
- {
- $request = Request::instance();
- if(!$request->isPost()) return JsonService::fail('参数错误!');
- $addressInfo = UtilService::postMore([
- ['address',[]],
- ['is_default',false],
- ['real_name',''],
- ['post_code',''],
- ['phone',''],
- ['detail',''],
- ['id',0]
- ],$request);
- $addressInfo['province'] = $addressInfo['address']['province'];
- $addressInfo['city'] = $addressInfo['address']['city'];
- $addressInfo['district'] = $addressInfo['address']['district'];
- $addressInfo['is_default'] = $addressInfo['is_default'] == true ? 1 : 0;
- $addressInfo['uid'] = $this->userInfo['uid'];
- unset($addressInfo['address']);
- if($addressInfo['id'] && UserAddress::be(['id'=>$addressInfo['id'],'uid'=>$this->userInfo['uid'],'is_del'=>0])){
- $id = $addressInfo['id'];
- unset($addressInfo['id']);
- if(UserAddress::edit($addressInfo,$id,'id')){
- if($addressInfo['is_default'])
- UserAddress::setDefaultAddress($id,$this->userInfo['uid']);
- return JsonService::successful();
- }else
- return JsonService::fail('编辑收货地址失败!');
- }else{
- if($address = UserAddress::set($addressInfo)){
- if($addressInfo['is_default'])
- UserAddress::setDefaultAddress($address->id,$this->userInfo['uid']);
- return JsonService::successful();
- }else
- return JsonService::fail('添加收货地址失败!');
- }
- }
- /**
- * 获取一条用户地址
- * @param string $addressId
- * @return \think\response\Json
- */
- public function get_user_address($addressId = ''){
- $addressInfo = [];
- if($addressId && is_numeric($addressId) && UserAddress::be(['is_del'=>0,'id'=>$addressId,'uid'=>$this->userInfo['uid']])){
- $addressInfo = UserAddress::find($addressId);
- }
- return JsonService::successful($addressInfo);
- }
- /**
- * 获取默认地址
- * @return \think\response\Json
- */
- public function user_default_address()
- {
- $defaultAddress = UserAddress::getUserDefaultAddress($this->userInfo['uid'],'id,real_name,phone,province,city,district,detail,is_default');
- if($defaultAddress) return JsonService::successful('ok',$defaultAddress);
- else return JsonService::successful('empty',[]);
- }
- /**
- * 删除地址
- * @param string $addressId
- * @return \think\response\Json
- */
- public function remove_user_address($addressId = '')
- {
- if(!$addressId || !is_numeric($addressId)) return JsonService::fail('参数错误!');
- if(!UserAddress::be(['is_del'=>0,'id'=>$addressId,'uid'=>$this->userInfo['uid']]))
- return JsonService::fail('地址不存在!');
- if(UserAddress::edit(['is_del'=>'1'],$addressId,'id'))
- return JsonService::successful();
- else
- return JsonService::fail('删除地址失败!');
- }
- /**
- * 创建订单
- * @param string $key
- * @return \think\response\Json
- */
- public function create_order($key = '')
- {
- if(!$key) return JsonService::fail('参数错误!');
- if(StoreOrder::be(['order_id|unique'=>$key,'uid'=>$this->userInfo['uid'],'is_del'=>0]))
- return JsonService::status('extend_order','订单已生成',['orderId'=>$key,'key'=>$key]);
- list($addressId,$couponId,$payType,$useIntegral,$mark,$combinationId,$pinkId,$seckill_id,$formId,$bargainId) = UtilService::postMore([
- 'addressId','couponId','payType','useIntegral','mark',['combinationId',0],['pinkId',0],['seckill_id',0],['formId',''],['bargainId','']
- ],Request::instance(),true);
- $payType = strtolower($payType);
- if($bargainId) StoreBargainUser::setBargainUserStatus($bargainId,$this->userInfo['uid']);//修改砍价状态
- if($pinkId) if(StorePink::getIsPinkUid($pinkId,$this->userInfo['uid'])) return JsonService::status('ORDER_EXIST','订单生成失败,你已经在该团内不能再参加了',['orderId'=>StoreOrder::getStoreIdPink($pinkId,$this->userInfo['uid'])]);
- if($pinkId) if(StoreOrder::getIsOrderPink($pinkId,$this->userInfo['uid'])) return JsonService::status('ORDER_EXIST','订单生成失败,你已经参加该团了,请先支付订单',['orderId'=>StoreOrder::getStoreIdPink($pinkId,$this->userInfo['uid'])]);
- $order = StoreOrder::cacheKeyCreateOrder($this->userInfo['uid'],$key,$addressId,$payType,$useIntegral,$couponId,$mark,$combinationId,$pinkId,$seckill_id,$bargainId);
- $orderId = $order['order_id'];
- $info = compact('orderId','key');
- if($orderId){
- if($payType == 'weixin'){
- $orderInfo = StoreOrder::where('order_id',$orderId)->find();
- if(!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if($orderInfo['paid']) exception('支付已支付!');
- //如果支付金额为0
- if(bcsub((float)$orderInfo['pay_price'],0,2) <= 0){
- //创建订单jspay支付
- if(StoreOrder::jsPayPrice($orderId,$this->userInfo['uid'],$formId))
- return JsonService::status('success','微信支付成功',$info);
- else
- return JsonService::status('pay_error',StoreOrder::getErrorInfo());
- }else{
- try{
- $jsConfig = StoreOrder::jsPay($orderId);//创建订单jspay
- }catch (\Exception $e){
- return JsonService::status('pay_error',$e->getMessage(),$info);
- }
- $info['jsConfig'] = $jsConfig;
- return JsonService::status('wechat_pay','订单创建成功',$info);
- }
- }else if($payType == 'yue'){
- if(StoreOrder::yuePay($orderId,$this->userInfo['uid'],$formId))
- return JsonService::status('success','余额支付成功',$info);
- else
- return JsonService::status('pay_error',StoreOrder::getErrorInfo());
- }else if($payType == 'offline'){
- // RoutineTemplate::sendOrderSuccess($formId,$orderId);//发送模板消息
- return JsonService::status('success','订单创建成功',$info);
- }
- }else{
- return JsonService::fail(StoreOrder::getErrorInfo('订单生成失败!'));
- }
- }
- /**
- * 获取订单列表
- * @param string $type
- * @param int $first
- * @param int $limit
- * @param string $search
- * @return \think\response\Json
- */
- public function get_user_order_list($type = '',$first = 0, $limit = 8,$search = '')
- {
- // StoreOrder::delCombination();//删除拼团未支付订单
- if($search){
- $order = StoreOrder::searchUserOrder($this->userInfo['uid'],$search)?:[];
- $list = $order == false ? [] : [$order];
- }else{
- $list = StoreOrder::getUserOrderList($this->userInfo['uid'],$type,$first,$limit);
- }
- foreach ($list as $k=>$order){
- $list[$k] = StoreOrder::tidyOrder($order,true);
- if($list[$k]['_status']['_type'] == 3){
- foreach ($order['cartInfo']?:[] as $key=>$product){
- $list[$k]['cartInfo'][$key]['is_reply'] = StoreProductReply::isReply($product['unique'],'product');
- }
- }
- }
- return JsonService::successful($list);
- }
- /**
- * 订单详情页
- * @param string $order_id
- * @return \think\response\Json
- */
- public function get_order($uni = ''){
- if($uni == '') return JsonService::fail('参数错误');
- $order = StoreOrder::getUserOrderDetail($this->userInfo['uid'],$uni);
- $order = $order->toArray();
- $order['add_time'] = date('Y-m-d H:i:s',$order['add_time']);
- $order['favourable_price'] = bcadd($order['deduction_price'],$order['coupon_price'],2);
- if(!$order) return JsonService::fail('订单不存在');
- return JsonService::successful(StoreOrder::tidyOrder($order,true));
- }
- /**
- * 获取订单内的某个产品信息
- * @param string $uni
- * @param string $productId
- * @return \think\response\Json
- */
- public function get_order_product($unique = ''){
- if(!$unique || !StoreOrderCartInfo::be(['unique'=>$unique]) || !($cartInfo = StoreOrderCartInfo::where('unique',$unique)->find())) return JsonService::fail('评价产品不存在!');
- return JsonService::successful($cartInfo);
- }
- /**
- * 删除订单
- * @param string $uni
- * @return \think\response\Json
- */
- public function user_remove_order($uni = '')
- {
- if(!$uni) return JsonService::fail('参数错误!');
- $res = StoreOrder::removeOrder($uni,$this->userInfo['uid']);
- if($res)
- return JsonService::successful();
- else
- return JsonService::fail(StoreOrder::getErrorInfo());
- }
- //TODO 支付订单
- /**
- * 支付订单
- * @param string $uni
- * @return \think\response\Json
- */
- public function pay_order($uni = '',$paytype='weixin')
- {
- if(!$uni) return JsonService::fail('参数错误!');
- $order = StoreOrder::getUserOrderDetail($this->userInfo['uid'],$uni);
- if(!$order) return JsonService::fail('订单不存在!');
- if($order['paid']) return JsonService::fail('该订单已支付!');
- if($order['pink_id']) if(StorePink::isPinkStatus($order['pink_id'])) return JsonService::fail('该订单已失效!');
- $cartInfoId = $order['cart_id'];
- $resCartProductStatus = true;
- foreach ($cartInfoId as $key=>&$item){
- $resCartProductStatus = $resCartProductStatus && StoreCart::decideCartProductOverdue($item);
- }
- if(!$resCartProductStatus) return JsonService::fail(StoreCart::getErrorInfo('订单产品已失效,请重新下单'));
- $order['pay_type'] = $paytype;//重新支付选择支付方式
- if($order['pay_type'] == 'weixin'){
- try{
- $jsConfig = StoreOrder::jsPay($order);//订单列表发起支付
- }catch (\Exception $e){
- return JsonService::fail($e->getMessage());
- }
- return JsonService::status('wechat_pay',['jsConfig'=>$jsConfig,'order_id'=>$order['order_id']]);
- }else if($order['pay_type'] == 'yue'){
- if($res = StoreOrder::yuePay($order['order_id'],$this->userInfo['uid']))
- return JsonService::successful('余额支付成功');
- else
- return JsonService::fail(StoreOrder::getErrorInfo());
- }else if($order['pay_type'] == 'offline'){
- StoreOrder::createOrderTemplate($order);
- return JsonService::successful('订单创建成功');
- }
- }
- /**
- * 申请退款
- * @param string $uni
- * @param string $text
- * @return \think\response\Json
- */
- public function apply_order_refund(Request $request,$uni = '')
- {
- $data = UtilService::postMore([
- ['text',''],
- ['refund_reason_wap_img',''],
- ['refund_reason_wap_explain',''],
- ],$request);
- if($data['refund_reason_wap_img']) $data['refund_reason_wap_img'] = explode(',',$data['refund_reason_wap_img']);
- if(!$uni || $data['text'] == '') return JsonService::fail('参数错误!');
- $res = StoreOrder::orderApplyRefund($uni,$this->userInfo['uid'],$data['text'],$data['refund_reason_wap_explain'],$data['refund_reason_wap_img']);
- if($res)
- return JsonService::successful();
- else
- return JsonService::fail(StoreOrder::getErrorInfo());
- }
- /**
- * 用户确认收货
- * @param string $uni
- * @return \think\response\Json
- */
- public function user_take_order($uni = '')
- {
- if(!$uni) return JsonService::fail('参数错误!');
- $res = StoreOrder::takeOrder($uni,$this->userInfo['uid']);
- if($res)
- return JsonService::successful();
- else
- return JsonService::fail(StoreOrder::getErrorInfo());
- }
- /**
- * 充值
- * @param int $price
- * @return \think\response\Json
- */
- public function user_wechat_recharge($price = 0)
- {
- if(!$price || $price <=0) return JsonService::fail('参数错误');
- $storeMinRecharge = SystemConfigService::get('store_user_min_recharge');
- if($price < $storeMinRecharge) return JsonService::fail('充值金额不能低于'.$storeMinRecharge);
- $rechargeOrder = UserRecharge::addRecharge($this->userInfo['uid'],$price);
- if(!$rechargeOrder) return JsonService::fail('充值订单生成失败!');
- try{
- return JsonService::successful(UserRecharge::jsPay($rechargeOrder));
- }catch (\Exception $e){
- return JsonService::fail($e->getMessage());
- }
- }
- /**
- * 余额使用记录
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function user_balance_list($first = 0,$limit = 8)
- {
- $list = UserBill::where('uid',$this->userInfo['uid'])->where('category','now_money')
- ->field('mark,pm,number,add_time')
- ->where('status',1)->order('add_time DESC')->limit($first,$limit)->select()->toArray();
- foreach ($list as &$v){
- $v['add_time'] = date('Y/m/d H:i',$v['add_time']);
- }
- return JsonService::successful($list);
- }
- /**
- * 积分使用记录
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function user_integral_list($first = 0,$limit = 8)
- {
- $list = UserBill::where('uid',$this->userInfo['uid'])->where('category','integral')
- ->field('mark,pm,number,add_time')
- ->where('status',1)->order('add_time DESC')->limit($first,$limit)->select()->toArray();
- foreach ($list as &$v){
- $v['add_time'] = date('Y/m/d H:i',$v['add_time']);
- $v['number'] = floatval($v['number']);
- }
- return JsonService::successful($list);
- }
- /**
- * 评价订单
- * @param string $unique
- * @return \think\response\Json
- */
- public function user_comment_product($unique = '')
- {
- if(!$unique) return JsonService::fail('参数错误!');
- $cartInfo = StoreOrderCartInfo::where('unique',$unique)->find();
- $uid = $this->userInfo['uid'];
- if(!$cartInfo || $uid != $cartInfo['cart_info']['uid']) return JsonService::fail('评价产品不存在!');
- if(StoreProductReply::be(['oid'=>$cartInfo['oid'],'unique'=>$unique]))
- return JsonService::fail('该产品已评价!');
- $group = UtilService::postMore([
- ['comment',''],['pics',[]],['product_score',5],['service_score',5]
- ],Request::instance());
- $group['comment'] = htmlspecialchars(trim($group['comment']));
- if($group['product_score'] < 1) return JsonService::fail('请为产品评分');
- else if($group['service_score'] < 1) return JsonService::fail('请为商家服务评分');
- if($cartInfo['cart_info']['combination_id']) $productId = $cartInfo['cart_info']['product_id'];
- else if($cartInfo['cart_info']['seckill_id']) $productId = $cartInfo['cart_info']['product_id'];
- else if($cartInfo['cart_info']['bargain_id']) $productId = $cartInfo['cart_info']['product_id'];
- else $productId = $cartInfo['product_id'];
- $group = array_merge($group,[
- 'uid'=>$uid,
- 'oid'=>$cartInfo['oid'],
- 'unique'=>$unique,
- 'product_id'=>$productId,
- 'reply_type'=>'product'
- ]);
- StoreProductReply::beginTrans();
- $res = StoreProductReply::reply($group,'product');
- if(!$res) {
- StoreProductReply::rollbackTrans();
- return JsonService::fail('评价失败!');
- }
- try{
- // HookService::listen('store_product_order_reply',$group,$cartInfo,false,StoreProductBehavior::class);
- StoreOrder::checkOrderOver($cartInfo['oid']);
- }catch (\Exception $e){
- StoreProductReply::rollbackTrans();
- return JsonService::fail($e->getMessage());
- }
- StoreProductReply::commitTrans();
- return JsonService::successful();
- }
- /**
- * 上传图片
- * @param string $filename
- * @return \think\response\Json
- */
- public function upload(Request $request)
- {
- $data = UtilService::postMore([['filename','']],$request);
- $res = UploadService::image($data['filename'],'store/comment');
- if($res->status == 200)
- return JsonService::successful('图片上传成功!',['name'=>$res->fileInfo->getSaveName(),'url'=>UploadService::pathToUrl($res->dir)]);
- else
- return JsonService::fail($res->error);
- }
- /**
- * 获取一级和二级分类
- * @return \think\response\Json
- */
- public function get_product_category()
- {
- $parentCategory = StoreCategory::pidByCategory(0,'id,cate_name')->toArray();
- foreach ($parentCategory as $k=>$category){
- $category['child'] = StoreCategory::pidByCategory($category['id'],'id,cate_name')->toArray();
- $parentCategory[$k] = $category;
- }
- return JsonService::successful($parentCategory);
- }
- /**
- * 获取一级推荐人
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_spread_list($first = 0,$limit = 20)
- {
- $list = User::where('spread_uid',$this->userInfo['uid'])->field('uid,nickname,avatar,add_time')->limit($first,$limit)->order('add_time DESC')->select()->toArray();
- foreach ($list as $k=>&$user){
- $user['add_time'] = date('Y/m/d',$user['add_time']);
- $user['price'] = StoreOrder::getUserPrice($user['uid']);
- }
- $count = User::where('spread_uid',$this->userInfo['uid'])->field('uid,nickname,avatar,add_time')->count();
- $data['count'] = $count;
- $data['list'] = $list;
- return JsonService::successful($data);
- }
- /**
- * 获取二级推荐人
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_spread_list_two($two_uid=0,$first = 0,$limit = 20)
- {
- $list = User::where('spread_uid',$two_uid)->field('uid,nickname,avatar,add_time')->limit($first,$limit)->order('add_time DESC')->select()->toArray();
- foreach ($list as $k=>&$user){
- $user['add_time'] = date('Y/m/d',$user['add_time']);
- $user['price'] = StoreOrder::getUserPrice($user['uid']);
- }
- $count = User::where('spread_uid',$two_uid)->field('uid,nickname,avatar,add_time')->count();
- $data['count'] = $count;
- $data['list'] = $list;
- return JsonService::successful($data);
- }
- /**
- * 领取优惠券
- * @param string $couponId
- * @return \think\response\Json
- */
- public function user_get_coupon($couponId = '')
- {
- if(!$couponId || !is_numeric($couponId)) return JsonService::fail('参数错误!');
- if(StoreCouponIssue::issueUserCoupon($couponId,$this->userInfo['uid'])){
- return JsonService::successful('领取成功');
- }else{
- return JsonService::fail(StoreCouponIssue::getErrorInfo('领取失败!'));
- }
- }
- /**
- * 获取产品评论
- * @param string $productId
- * @param int $first
- * @param int $limit
- * @param string $filter
- * @return \think\response\Json
- */
- public function product_reply_list($productId = '',$first = 0,$limit = 8, $filter = 'all')
- {
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误!');
- $list = StoreProductReply::getProductReplyList($productId,$filter,$first,$limit);
- if($list){
- foreach ($list as $k=>$v){
- foreach ($v['pics'] as $kk=>$vv){
- $list[$k]['pics'] = explode(',',$vv);
- }
- }
- }
- return JsonService::successful($list);
- }
- /**
- * 获取商品属性数据
- * @param string $productId
- * @return \think\response\Json
- */
- public function product_attr_detail($productId = '')
- {
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误!');
- list($productAttr,$productValue) = StoreProductAttr::getProductAttrDetail($productId);
- return JsonService::successful(compact('productAttr','productValue'));
- }
- /**
- * 获取用户所有地址
- * @return \think\response\Json
- */
- public function user_address_list()
- {
- $list = UserAddress::getUserValidAddressList($this->userInfo['uid'],'id,real_name,phone,province,city,district,detail,is_default');
- return JsonService::successful($list);
- }
- /**
- * 用户通知
- * @param int $page
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_notice_list($page = 0, $limit = 8)
- {
- $list = UserNotice::getNoticeList($this->userInfo['uid'],$page,$limit);
- return JsonService::successful($list);
- }
- /**
- * 修改用户通知为已查看
- * @param $nid
- * @return \think\response\Json
- */
- public function see_notice($nid){
- UserNotice::seeNotice($this->userInfo['uid'],$nid);
- return JsonService::successful();
- }
- public function get_user_brokerage_list($uid, $first = 0,$limit = 8)
- {
- if(!$uid)
- return $this->failed('用户不存在');
- $list = UserBill::field('A.mark,A.add_time,A.number,A.pm')->alias('A')->limit($first,$limit)
- ->where('A.category','now_money')->where('A.type','brokerage')
- ->where('A.uid',$this->userInfo['uid'])
- ->join('__STORE_ORDER__ B','A.link_id = B.id AND B.uid = '.$uid)->select()->toArray();
- return JsonService::successful($list);
- }
-
- public function user_extract()
- { $request = Request::instance();
- $list=$request->param();
- $data=$list['lists'];
- if(UserExtract::userExtract($this->userInfo,$data))
- return JsonService::successful('申请提现成功!');
- else
- return JsonService::fail(UserExtract::getErrorInfo());
- }
- /*
- * 提现列表
- */
- public function extract($first = 0,$limit = 8)
- {
- $list=UserExtract::where('uid',$this->userInfo['uid'])->order('add_time desc')->limit($first,$limit)->select()->toArray();
- foreach($list as &$v){
- $v['add_time']=date('Y/m/d',$v['add_time']);
- }
-
- return JsonService::successful($list);
- }
- /**
- * 用户下级的订单
- * @param int $first
- * @param int $limit
- */
- public function subordinateOrderlist($first = 0, $limit = 8){
- $request = Request::instance();
- $lists=$request->param();
- $xUid = $lists['uid'];
- $status = $lists['status'];
- if($status == 0) $type='';
- elseif($status == 1) $type=4;
- elseif($status == 2) $type=3;
- else return false;
- $list = [];
- if(!$xUid){
- $arr = User::where('spread_uid',$this->userInfo['uid'])->column('uid');
- foreach($arr as $v) $list = StoreOrder::getUserOrderList($v,$type,$first,$limit);
- }else $list = StoreOrder::getUserOrderList($xUid,$type,$first,$limit);
- foreach ($list as $k=>$order){
- $list[$k] = StoreOrder::tidyOrder($order,true);
- if($list[$k]['_status']['_type'] == 3){
- foreach ($order['cartInfo']?:[] as $key=>$product){
- $list[$k]['cartInfo'][$key]['is_reply'] = StoreProductReply::isReply($product['unique'],'product');
- }
- }
- }
- return JsonService::successful($list);
- }
- /**
- * 用户下级的订单
- * @param int $first
- * @param int $limit
- */
- public function subordinateOrderlistmoney()
- {
- $request = Request::instance();
- $lists=$request->param();
- $status = $lists['status'];
- $type = '';
- if($status == 1) $type = 4;
- elseif($status == 2) $type = 3;
- $arr = User::where('spread_uid',$this->userInfo['uid'])->column('uid');
- $list = StoreOrder::getUserOrderCount(implode(',',$arr),$type);
- $price = [];
- // if(!empty($list)) foreach ($list as $k=>$v) $price[]=$v['pay_price'];
- if(!empty($list)) foreach ($list as $k=>$v) $price[]=$v;
- $cont = count($list);
- $sum = array_sum($price);
- return JsonService::successful(['cont'=>$cont,'sum'=>$sum]);
- }
- /*
- * 昨日推广佣金
- */
- public function yesterdayCommission(){
- $money=UserBill::where('uid',$this->userInfo['uid'])->where('category','now_money')->where('type','brokerage')->where('pm',1)->where('status',1)->whereTime('add_time', 'yesterday')->column('number');
- $sum= array_sum($money);
- return JsonService::successful($sum);
- }
- /*
- * 累计已提金额
- */
- public function extractsum(){
- $money=UserExtract::where('uid',$this->userInfo['uid'])->where('status',1)->column('extract_price');
- $sum= array_sum($money);
- return JsonService::successful($sum);
- }
- /**
- * 获取一条优惠券
- * @param int $couponId
- * @return \think\response\Json
- */
- public function get_coupon_rope($couponId = 0){
- if(!$couponId) return JsonService::fail('参数错误');
- $couponUser = StoreCouponUser::validAddressWhere()->where('id',$couponId)->where('uid',$this->userInfo['uid'])->find();
- return JsonService::successful($couponUser);
- }
- /**
- * 获取 可以领取的优惠券
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_issue_coupon_list($limit = 2)
- {
- $list = StoreCouponIssue::validWhere('A')->join('__STORE_COUPON__ B','A.cid = B.id')
- ->field('A.*,B.coupon_price,B.use_min_price')->order('B.sort DESC,A.id DESC')->limit($limit)->select()->toArray()?:[];
- foreach ($list as $k=>$v){
- $list[$k]['is_use'] = StoreCouponIssueUser::be(['uid'=>$this->userInfo['uid'],'issue_coupon_id'=>$v['id']]);
- }
- return JsonService::successful($list);
- }
- public function clear_cache($uni = '')
- {
- if($uni)CacheService::clear();
- }
- /**
- * 获取今天正在拼团的人的头像和名称
- * @return \think\response\Json
- */
- public function get_pink_second_one(){
- $addTime = mt_rand(time()-30000,time());
- $storePink = StorePink::where('p.add_time','GT',$addTime)->alias('p')->where('p.status',1)->join('User u','u.uid=p.uid')->field('u.nickname,u.avatar as src')->find();
- return JsonService::successful($storePink);
- }
- /**
- * 再来一单
- * @param string $uni
- */
- public function order_details($uni = ''){
- if(!$uni) return JsonService::fail('参数错误!');
- $order = StoreOrder::getUserOrderDetail($this->userInfo['uid'],$uni);
- if(!$order) return JsonService::fail('订单不存在!');
- $order = StoreOrder::tidyOrder($order,true);
- $res = array();
- foreach ($order['cartInfo'] as $v) {
- if($v['combination_id']) return JsonService::fail('拼团产品不能再来一单,请在拼团产品内自行下单!');
- else $res[] = StoreCart::setCart($this->userInfo['uid'], $v['product_id'], $v['cart_num'], isset($v['productInfo']['attrInfo']['unique']) ? $v['productInfo']['attrInfo']['unique'] : '', 'product', 0, 0);
- }
- $cateId = [];
- foreach ($res as $v){
- if(!$v) return JsonService::fail('再来一单失败,请重新下单!');
- $cateId[] = $v['id'];
- }
- return JsonService::successful('ok',implode(',',$cateId));
- }
- /**
- * 获取分销二维码
- * @return \think\response\Json
- */
- public function get_code(){
- header('content-type:image/jpg');
- if(!$this->userInfo['uid']) return JsonService::fail('授权失败,请重新授权');
- $path = makePathToUrl('routine/code');
- if($path == '')
- return JsonService::fail('生成上传目录失败,请检查权限!');
- $picname = $path.'/'.$this->userInfo['uid'].'.jpg';
- $domain = SystemConfigService::get('site_url').'/';
- $domainTop = substr($domain,0,5);
- if($domainTop != 'https') $domain = 'https:'.substr($domain,5,strlen($domain));
- if(file_exists($picname)) return JsonService::successful($domain.$picname);
- else{
- $res = RoutineCode::getCode($this->userInfo['uid'],$picname);
- if($res) file_put_contents($picname,$res);
- else return JsonService::fail('二维码生成失败');
- }
- return JsonService::successful($domain.$picname);
- }
- /**
- * TODO 获取分销二维码不存入小程序二维码表中
- * @return \think\response\Json
- */
- public function get_routine_code(){
- header('content-type:image/jpg');
- if(!$this->userInfo['uid']) return JsonService::fail('授权失败,请重新授权');
- $path = makePathToUrl('routine/code');
- if($path == '')
- return JsonService::fail('生成上传目录失败,请检查权限!');
- $picname = $path.'/'.$this->userInfo['uid'].'.jpg';
- $domain = SystemConfigService::get('site_url').'/';
- $domainTop = substr($domain,0,5);
- if($domainTop != 'https') $domain = 'https:'.substr($domain,5,strlen($domain));
- if(file_exists($picname)) return JsonService::successful($domain.$picname);
- else{
- // $res = RoutineCode::getRoutineCode($this->userInfo['uid']);
- $res = MiniProgramService::appCodeUnlimitService($this->userInfo['uid'])->__toString();
- if($res){
- file_put_contents($picname,$res);
- }else return JsonService::fail('二维码生成失败');
- }
- return JsonService::successful($domain.$picname);
- }
- /**
- * 绑定推荐人
- * @param Request $request
- * @return \think\response\Json
- */
- public function spread_uid(Request $request){
- $data = UtilService::postMore(['spread_uid',0],$request);
- if($data['spread_uid']){
- if(!$this->userInfo['spread_uid']){
- $res = User::edit(['spread_uid'=>$data['spread_uid']],$this->userInfo['uid']);
- if($res) return JsonService::successful('绑定成功');
- else return JsonService::successful('绑定失败');
- }else return JsonService::fail('已存在被推荐人');
- }else return JsonService::fail('没有推荐人');
- }
- /**
- * 获取砍价列表
- * @return \think\response\Json
- */
- public function get_bargain_list($limit = 10){
- $bargain = StoreBargain::getList();
- $bargain = StoreBargainUser::getUserList($bargain,$limit);
- $lovely = GroupDataService::getData('routine_lovely')?:[];//banner图
- $banner = GroupDataService::getData('bargain_banner')?:[];//banner图
- $banner = $banner[0];
- $bargainUser = StoreBargainUser::getBargainUserStatusSuccess();
- $data['bargain'] = $bargain;
- $data['lovely'] = $lovely[2];
- $data['banner'] = $banner;
- $data['bargainUser'] = $bargainUser;
- return JsonService::successful($data);
- }
- /**
- * 砍价详情
- * @param int $bargainId
- * @return \think\response\Json
- */
- public function get_bargain($bargainId = 0){
- if(!$bargainId) return JsonService::fail('参数错误');
- $bargain = StoreBargain::getBargainTerm($bargainId);
- if(empty($bargain)) return JsonService::fail('砍价已结束');
- $bargain['time'] = time();
- return JsonService::successful($bargain);
- }
- /**
- * 获取人数
- * @param int $count
- * @return \think\response\Json
- */
- public function get_bargain_count($count = 0){
- $data['lookCount'] = StoreBargain::getBargainLook()['look'];//观看人数
- $data['shareCount'] = StoreBargain::getBargainShare()['share'];//观看人数
- $data['userCount'] = StoreBargainUser::count();//参与人数
- return JsonService::successful($data);
- }
- /**
- * 添加砍价分享次数
- * @param int $bargainId
- */
- public function add_share_bargain($bargainId = 0){
- if(!$bargainId) return JsonService::successful();
- StoreBargain::addBargainShare($bargainId);
- return JsonService::successful();
- }
- /**
- * 添加砍价浏览次数
- * @param int $bargainId
- */
- public function add_look_bargain($bargainId = 0){
- if(!$bargainId) return JsonService::successful();
- StoreBargain::addBargainLook($bargainId);
- return JsonService::successful();
- }
- /**
- * 获取砍价帮
- * @param int $bargainId
- * @param int $uid
- * @return \think\response\Json
- */
- public function get_bargain_user($bargainId = 0,$bargainUid = 0,$limit = 15){
- if(!$bargainId || !$bargainUid) return JsonService::fail('参数错误');
- $bargainUserTableId = StoreBargainUser::setUserBargain($bargainId,$bargainUid);
- $storeBargainUserHelp = StoreBargainUserHelp::getList($bargainUserTableId,$limit);
- return JsonService::successful($storeBargainUserHelp);
- }
- /**
- * 我的砍价
- * @param int $bargainId
- * @return \think\response\Json
- */
- public function mycut($bargainId = 0){
- if(!$bargainId ) return JsonService::fail('参数错误');
- $data= StoreBargainUser::where('bargain_id',$bargainId)->where('uid',$this->userInfo['uid'])->where('status',1)->find();
- return JsonService::successful($data);
- }
- /**
- * 参与砍价产品
- * @param int $bargainId
- * @return \think\response\Json
- */
- public function set_bargain($bargainId = 0){
- if(!$bargainId) return JsonService::fail('参数错误');
- $res = StoreBargainUser::setBargain($bargainId,$this->userInfo['uid']);
- if($res) {
- $data['id'] = $res->id;
- return JsonService::successful('参与成功',$data);
- }
- else return JsonService::fail('参与失败');
- }
- /**
- * 判断当前登录人是否参与砍价
- * @param int $bargainId
- * @return \think\response\Json
- */
- public function is_bargain_user($bargainId = 0){
- if(!$bargainId) return JsonService::fail('参数错误');
- $data=StoreBargainUser::isBargainUser($bargainId,$this->userInfo['uid']);
- if($data) return JsonService::successful($data);
- else return JsonService::fail('没有参与砍价');
- }
- /*
- * 已砍掉的金额
- */
- public function speed_of_progress($bargainId = 0){
- if(!$bargainId) return JsonService::fail('参数错误');
- $price= StoreBargainUser::where('bargain_id',$bargainId)->where('status',1)->where('uid',$this->userInfo['uid'])->value('price');
- return JsonService::successful($price);
- }
- /**
- * 帮好友砍价
- * @param int $bargainId
- * @param int $bargainUserId
- * @return \think\response\Json
- */
- public function set_bargain_help($bargainId = 0,$bargainUserId = 0){
- if(!$bargainId || !$bargainUserId) return JsonService::fail('参数错误');
- $res = StoreBargainUserHelp::setBargainUserHelp($bargainId,$bargainUserId,$this->userInfo['uid']);
- if($res) {
- if(StoreBargainUserHelp::getSurplusPrice($bargainId,$bargainUserId) <= 0){
- $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
- $bargain = StoreBargain::where('id',$bargainId)->find()->toArray();
- $bargainUser = StoreBargainUser::where('id',$bargainUserTableId)->find()->toArray();
- RoutineTemplate::sendBargainSuccess($bargain,$bargainUser,$bargainUserId);//发送模板消息
- }
- return JsonService::successful('砍价成功',$res);
- }
- else return JsonService::fail('砍价失败');
- }
- /**
- * 获取砍价帮总人数、剩余金额、进度条
- * @param int $bargainId
- * @param int $bargainUserId
- * @return \think\response\Json
- */
- public function get_bargain_help_count($bargainId = 0,$bargainUserId = 0){
- if(!$bargainId || !$bargainUserId) return JsonService::fail('参数错误');
- $count = StoreBargainUserHelp::getBargainUserHelpPeopleCount($bargainId,$bargainUserId);
- $price = StoreBargainUserHelp::getSurplusPrice($bargainId,$bargainUserId);
- $pricePercent = StoreBargainUserHelp::getSurplusPricePercent($bargainId,$bargainUserId);
- $data['count'] = $count;
- $data['price'] = $price;
- $data['pricePercent'] = $pricePercent;
- return JsonService::successful($data);
- }
- /**
- * 判断当前砍价是否开启
- * @param int $bargainId
- * @return \think\response\Json
- */
- public function is_bargain_status($bargainId = 0){
- if(!$bargainId) return JsonService::fail('参数错误');
- if(!StoreBargain::setBargainStatus($bargainId)) return JsonService::successful();
- else return JsonService::fail();
- }
- /**
- * 判断用户是否可以砍价
- * @param int $bargainId
- * @param int $bargainUserId
- */
- public function is_bargain_user_help($bargainId = 0,$bargainUserId = 0){
- if(!$bargainId || !$bargainUserId) return JsonService::fail('参数错误');
- if(StoreBargainUserHelp::isBargainUserHelpCount($bargainId,$bargainUserId,$this->userInfo['uid'])) return JsonService::successful('请稍后再帮助好友砍价');
- else return JsonService::fail('您不能再帮忙砍价了');
- }
- /**
- * 修改砍价状态为失败
- * @param int $bargainUserTableId
- */
- public function set_user_bargain_status($bargainUserTableId = 0){
- if(!$bargainUserTableId) return JsonService::fail('参数错误');
- if(StoreBargainUser::editBargainUserStatus($bargainUserTableId)) return JsonService::successful('ok');
- else return JsonService::fail('no');
- }
- /**
- * 获取用户信息
- * @param int $uid
- * @return \think\response\Json
- */
- public function get_user_info_uid($userId = 0){
- if(!$userId) return JsonService::fail('参数错误');
- $res = User::getUserInfo($userId);
- if($res) return JsonService::successful($res);
- else return JsonService::fail(User::getErrorInfo());
- }
- /**
- * 获取砍价产品 个人中心 我的砍价
- */
- public function get_user_bargain_all(){
- $list = StoreBargainUser::getBargainUserAll($this->userInfo['uid']);
- if($list){
- foreach ($list as $k=>$v){
- $list[$k]['helpCount'] = StoreBargainUserHelp::getBargainUserHelpPeopleCount($v['bargain_id'],$this->userInfo['uid']);
- }
- return JsonService::successful($list);
- }else return JsonService::fail('暂无参与砍价');
- }
- /*
- * 查物流
- */
- public function express($uid,$uni = '')
- {
- if(!$uni || !($order = StoreOrder::getUserOrderDetail($uid,$uni))) return JsonService::fail('查询订单不存在!');
- if($order['delivery_type'] != 'express' || !$order['delivery_id']) return JsonService::fail('该订单不存在快递单号!');
- $cacheName = $uni.$order['delivery_id'];
- CacheService::rm($cacheName);
- $result = CacheService::get($cacheName,null);
- if($result === NULL){
- $result = Express::query($order['delivery_id']);
- if(is_array($result) &&
- isset($result['result']) &&
- isset($result['result']['deliverystatus']) &&
- $result['result']['deliverystatus'] >= 3)
- $cacheTime = 0;
- else
- $cacheTime = 1800;
- CacheService::set($cacheName,$result,$cacheTime);
- }
- if($result) return JsonService::successful([ 'order'=>$order, 'express'=>$result]);
- }
- /**
- * 收集发送模板信息的formID
- * @param string $formId
- */
- public function get_form_id($formId = ''){
- if(!strlen(trim($formId)) || $formId == 'the formId is a mock one') return JsonService::fail('no');
- $data['form_id'] = $formId;
- $data['uid'] = $this->userInfo['uid'];
- $data['status'] = 1;
- $data['stop_time'] = bcadd(time(),bcmul(6,86400,0),0);
- RoutineFormId::set($data);
- return JsonService::successful();
- }
- /**
- * 获取拼团列表
- * @param int $offset
- * @param int $limit
- */
- public function get_combination_list($offset=0,$limit=20){
- $store_combination = StoreCombination::getAll($offset,$limit);
- return JsonService::successful($store_combination);
- }
- /**
- * 获取拼团列表顶部图
- * @param int $offset
- * @param int $limit
- */
- public function get_combination_list_banner(){
- $lovely = GroupDataService::getData('routine_lovely')?:[];//banner图
- $pic = isset($lovely[3])?$lovely[3]:'';
- return JsonService::successful($pic);
- }
- /**
- * 获取拼团产品详情
- * @param int $id
- */
- public function combination_detail($id = 0){
- if(!$id) return JsonService::fail('拼团不存在或已下架');
- $combinationOne = StoreCombination::getCombinationOne($id);
- if(!$combinationOne) return JsonService::fail('拼团不存在或已下架');
- $combinationOne['images'] = json_decode($combinationOne['images'],true);
- // $combinationOne['userLike'] = StoreProductRelation::isProductRelation($combinationOne['product_id'],$this->userInfo['uid'],'like');
- // $combinationOne['like_num'] = StoreProductRelation::productRelationNum($combinationOne['product_id'],'like');
- $combinationOne['userCollect'] = StoreProductRelation::isProductRelation($id,$this->userInfo['uid'],'collect','pink_product');
- $pink = StorePink::getPinkAll($id);//拼团列表
- $pindAll = array();
- foreach ($pink as $k=>$v){
- $pink[$k]['count'] = StorePink::getPinkPeople($v['id'],$v['people']);
- $pink[$k]['h'] = date('H',$v['stop_time']);
- $pink[$k]['i'] = date('i',$v['stop_time']);
- $pink[$k]['s'] = date('s',$v['stop_time']);
- $pindAll[] = $v['id'];//开团团长ID
- }
- $user = WechatUser::get($this->userInfo['uid'])->toArray();//用户信息
- $data['pink'] = $pink;
- $data['user'] = $user;
- $data['pindAll'] = $pindAll;
- $data['storeInfo'] = $combinationOne;
- $data['reply'] = StoreProductReply::getRecProductReply($combinationOne['product_id']);
- $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id',$combinationOne['product_id'])->count();
- // $data['mer_id'] = StoreProduct::where('id',$combinationOne['product_id'])->value('mer_id');
- return JsonService::successful($data);
- }
- /**
- * 开团页面
- * @param int $id
- * @return mixed
- */
- public function get_pink($id = 0){
- if(!$id) return JsonService::fail('参数错误');
- $pink = StorePink::getPinkUserOne($id);
- if(isset($pink['is_refund']) && $pink['is_refund']) {
- if($pink['is_refund'] != $pink['id']){
- $id = $pink['is_refund'];
- return $this->get_pink($id);
- }else{
- return JsonService::fail('订单已退款');
- }
- }
- if(!$pink) return JsonService::fail('参数错误');
- $pinkAll = array();//参团人 不包括团长
- $pinkT = array();//团长
- if($pink['k_id']){
- $pinkAll = StorePink::getPinkMember($pink['k_id']);
- $pinkT = StorePink::getPinkUserOne($pink['k_id']);
- }else{
- $pinkAll = StorePink::getPinkMember($pink['id']);
- $pinkT = $pink;
- }
- $store_combination = StoreCombination::getCombinationOne($pink['cid']);//拼团产品
- $count = count($pinkAll)+1;
- $count = (int)$pinkT['people']-$count;//剩余多少人
- $is_ok = 0;//判断拼团是否完成
- $idAll = array();
- $uidAll = array();
- if(!empty($pinkAll)){
- foreach ($pinkAll as $k=>$v){
- $idAll[$k] = $v['id'];
- $uidAll[$k] = $v['uid'];
- }
- }
- $userBool = 0;//判断当前用户是否在团内 0未在 1在
- $pinkBool = 0;//判断当前用户是否在团内 0未在 1在
- $idAll[] = $pinkT['id'];
- $uidAll[] = $pinkT['uid'];
- if($pinkT['status'] == 2){
- $pinkBool = 1;
- $is_ok = 1;
- }else{
- if(!$count){//组团完成
- $is_ok = 1;
- $idAll = implode(',',$idAll);
- $orderPinkStatus = StorePink::setPinkStatus($idAll);
- if($orderPinkStatus){
- if(in_array($this->userInfo['uid'],$uidAll)){
- StorePink::setPinkStopTime($idAll);
- if(StorePink::isTpl($uidAll,$pinkT['id'])) StorePink::orderPinkAfter($uidAll,$pinkT['id']);
- $pinkBool = 1;
- }else $pinkBool = 3;
- }else $pinkBool = 6;
- }
- else{
- if($pinkT['stop_time'] < time()){//拼团时间超时 退款
- if($pinkAll){
- foreach ($pinkAll as $v){
- if($v['uid'] == $this->userInfo['uid']){
- $res = StoreOrder::orderApplyRefund(StoreOrder::where('id',$v['order_id_key'])->value('order_id'),$this->userInfo['uid'],'拼团时间超时');
- if($res){
- if(StorePink::isTpl($v['uid'],$pinkT['id'])) StorePink::orderPinkAfterNo($v['uid'],$v['k_id']);
- $pinkBool = 2;
- }else return JsonService::fail(StoreOrder::getErrorInfo());
- }
- }
- }
- if($pinkT['uid'] == $this->userInfo['uid']){
- $res = StoreOrder::orderApplyRefund(StoreOrder::where('id',$pinkT['order_id_key'])->value('order_id'),$this->userInfo['uid'],'拼团时间超时');
- if($res){
- if(StorePink::isTpl($pinkT['uid'],$pinkT['id'])) StorePink::orderPinkAfterNo($pinkT['uid'],$pinkT['id']);
- $pinkBool = 2;
- }else return JsonService::fail(StoreOrder::getErrorInfo());
- }
- if(!$pinkBool) $pinkBool = 3;
- }
- }
- }
- $store_combination_host = StoreCombination::getCombinationHost();//获取推荐的拼团产品
- if(!empty($pinkAll)){
- foreach ($pinkAll as $v){
- if($v['uid'] == $this->userInfo['uid']) $userBool = 1;
- }
- }
- if($pinkT['uid'] == $this->userInfo['uid']) $userBool = 1;
- $combinationOne = StoreCombination::getCombinationOne($pink['cid']);
- if(!$combinationOne) return JsonService::fail('拼团不存在或已下架');
- $store_combination['userInfo'] = $this->userInfo;
- $data['pinkBool'] = $pinkBool;
- $data['is_ok'] = $is_ok;
- $data['userBool'] = $userBool;
- $data['store_combination'] = $store_combination;
- $data['pinkT'] = $pinkT;
- $data['pinkAll'] = $pinkAll;
- $data['count'] = $count;
- $data['store_combination_host'] = $store_combination_host;
- $data['current_pink_order'] = StorePink::getCurrentPink($id);
- return JsonService::successful($data);
- }
- /**
- * 购物车库存修改
- * @param int $cartId
- * @param int $cartNum
- */
- public function set_buy_cart_num($cartId = 0,$cartNum = 0){
- if(!$cartId) return JsonService::fail('参数错误');
- $res = StoreCart::edit(['cart_num'=>$cartNum],$cartId);
- if($res) return JsonService::successful();
- else return JsonService::fail('修改失败');
- }
- /**
- * 获取后台联系方式
- */
- public function get_site_phone(){
- $data = SystemConfig::getValue('site_service_phone');
- return JsonService::successful($data);
- }
- /**
- * 获取产品链接的二维码
- * @param string $path
- * @param int $width
- */
- // public function get_pages($path = '',$productId = 0,$width = 430){
- // if($path == '' || !$productId) return JsonService::fail('参数错误'); header('content-type:image/jpg');
- // if(!$this->userInfo['uid']) return JsonService::fail('授权失败,请重新授权');
- // $path = 'public/uploads/routinepage/'.$productId.'.jpg';
- // if(file_exists($path)) return JsonService::successful($path);
- // else file_put_contents($path,RoutineCode::getCode($this->userInfo['uid']));
- // return JsonService::successful($path);
- // }
- /**
- * 文章列表
- * @param int $cid
- * @param int $first
- * @param int $limit
- */
- public function get_cid_article($cid = 0,$first = 0,$limit = 8){
- $list = ArticleModel::cidByArticleList($cid,$first,$limit,'id,title,image_input,visit,add_time,synopsis,url')?:[];
- foreach ($list as &$article){
- $article['add_time'] = date('Y-m-d H:i',$article['add_time']);
- }
- $data['list'] = $list;
- return JsonService::successful($list);
- }
- /**
- * 获取热门文章
- */
- public function get_article_hot(){
- $hot = ArticleModel::getArticleListHot('id,title');
- return JsonService::successful($hot);
- }
- /**
- * 获取热门banner文章
- */
- public function get_article_banner(){
- $banner = ArticleModel::getArticleListBanner('id,title,image_input');
- return JsonService::successful($banner);
- }
- /**
- * 获取文章详情
- * @param int $id
- */
- public function visit($id = 0)
- {
- $content = ArticleModel::getArticleOne($id);
- if(!$content || !$content["status"]) return JsonService::fail('此文章已经不存在!');
- $content["visit"] = $content["visit"] + 1;
- $content['add_time'] = date('Y-m-d H:i:s',$content['add_time']);
- ArticleModel::edit(['visit'=>$content["visit"]],$id);//增加浏览次数
- return JsonService::successful($content);
- }
- /**
- * 产品海报二维码
- * @param int $id
- */
- public function product_promotion_code($id = 0){
- if(!$id) return JsonService::fail('参数错误');
- $count = StoreProduct::validWhere()->count();
- if(!$count) return JsonService::fail('参数错误');
- $path = UPLOAD_PATH.'/codepath/product/';
- $codePath = $path.$id.'_'.$this->userInfo['uid'].'.jpg';
- $domain = SystemConfigService::get('site_url').'/';
- if(!file_exists($codePath)){
- if(!is_dir($path)) mkdir($path,0777,true);
- $res = RoutineCode::getCode($this->userInfo['uid'],$codePath,[],'/pages/product-con/index?id='.$id,'product_spread');
- if($res) file_put_contents($codePath,$res);
- else return JsonService::fail('二维码生成失败');
- }
- return JsonService::successful($domain.$codePath);
- }
- /**
- * TODO 产品海报二维码 不存入小程序二维码表中
- * @param int $id
- */
- public function product_promotion_routine_code($id = 0){
- if(!$id) return JsonService::fail('参数错误');
- $count = StoreProduct::validWhere()->count();
- if(!$count) return JsonService::fail('参数错误');
- $path = UPLOAD_PATH.'/codepath/product/';
- $codePath = $path.$id.'_'.$this->userInfo['uid'].'.jpg';
- $domain = SystemConfigService::get('site_url').'/';
- if(!file_exists($codePath)){
- if(!is_dir($path)) mkdir($path,0777,true);
- $res = RoutineCode::getRoutineCode($this->userInfo['uid'],'pages/product-con/index',$id);
- if($res){
- $resStatus = json_decode($res,true);
- if(is_array($resStatus)) return JsonService::fail('错误码:'.$resStatus['errcode']);
- else file_put_contents($codePath,$res);
- }else return JsonService::fail('二维码生成失败');
- }
- return JsonService::successful($domain.$codePath);
- }
- // public function poster($id = 0){
- // if(!$id) return JsonService::fail('参数错误');
- // $productInfo = StoreProduct::getValidProduct($id,'store_name,id,price,image,code_path');
- // if(empty($productInfo)) return JsonService::fail('参数错误');
- // if(strlen($productInfo['code_path'])< 10) {
- // $path = 'public'.DS.'uploads'.DS.'codepath'.DS.'product';
- // $codePath = $path.DS.$productInfo['id'].'.jpg';
- // if(!file_exists($codePath)){
- // if(!is_dir($path)) mkdir($path,0777,true);
- //// $res = file_put_contents($codePath,RoutineCode::getPages('pages/product-con/index?id='.$productInfo['id']));
- // }
- // $res = StoreProduct::edit(['code_path'=>$codePath],$id);
- // if($res) $productInfo['code_path'] = $codePath;
- // else return JsonService::fail('没有查看权限');
- // }
- // $posterPath = createPoster($productInfo);
- // return JsonService::successful($posterPath);
- //
- // }
- /**
- * TODO 获取用户信息
- * @return \think\response\Json
- */
- public function get_user_info($is_sign = '',$discount = ''){
- if(is_object($this->userInfo)) $this->userInfo = $this->userInfo->toArray();
- if($is_sign){
- $this->userInfo['is_sign'] = UserSign::checkUserSigned($this->userInfo['uid']) ? true : false;
- $this->userInfo['sign_count'] = UserSign::userSignedCount($this->userInfo['uid']);
- // if(!User::where(['uid'=>$this->userInfo['uid'],'status'=>1])->whereTime('sign_time','yesterday')->count() && $this->userInfo['is_sign']==false){
- // User::update(['sign_num'=>0],['uid'=>$this->userInfo['uid']]);
- // $this->userInfo['sign_num']=0;
- // }
- }
- if($discount){
- list($grade_name,$discount_num,$sign_grade,$pic)=UserSign::getdiscount($this->get_sign_list(true,'sign_deploy'),$this->userInfo['integral']);
- $this->userInfo['grade_name']=$grade_name;
- $this->userInfo['pic']=$pic;
- $rank=User::where(['status'=>1])->where('uid','<>',$this->userInfo['uid'])->where('integral',$this->userInfo['integral'])->count();
- $this->userInfo['ranking']=User::where(['status'=>1])->where('integral','>',$this->userInfo['integral'])->count() +$rank +1;
- $count=User::where(['status'=>1])->count();
- $ranking=bcsub($count,$this->userInfo['ranking']);
- $this->userInfo['ratio']=bcdiv($ranking,$count,2) * 100;
- if($this->userInfo['ranking'] == 1)
- $this->userInfo['differ']=0;
- else{
- $integral=User::where(['status'=>1])->order('integral asc')->where('integral','>',$this->userInfo['integral'])->value('integral');
- $this->userInfo['differ']=$integral-$this->userInfo['integral'];
- }
- $this->userInfo['notice'] = UserNotice::getNotice($this->userInfo['uid']);
- }
- return JsonService::successful($this->userInfo);
- }
- /**
- * TODO 用户签到
- * @return \think\response\Json
- */
- public function user_sign()
- {
- $signed = UserSign::checkUserSigned($this->userInfo['uid']);
- if($signed) return JsonService::fail('已签到');
- if(false !== $integral = UserSign::sign($this->userInfo))
- return JsonService::successful('签到获得'.floatval($integral).'积分');
- // if(false !== $integral = UserSign::signFoodie($this->userInfo['uid'],$this->get_sign_list(true)))
- // return JsonService::successful('签到获得'.floatval($integral).'积分');
- else
- return JsonService::fail('签到失败!');
- }
- /**
- * TODO 判断用户是否签到
- */
- public function user_sign_status()
- {
- $signed = UserSign::checkUserSigned($this->userInfo['uid']);
- if($signed) return JsonService::successful('ok');
- else return JsonService::fail('no');
- }
- /*
- * TODO 获取系统配置签到列表
- * */
- public function get_sign_list($isarray = false,$data_key = 'sign_day_num'){
- $sign_day_num = GroupDataService::getData($data_key) ? :[];
- if($isarray === true) return $sign_day_num;
- return JsonService::successful($sign_day_num);
- }
- /**
- * TODO 获取签到记录
- */
- public function get_sign_log(){
- $where = UtilService::getMore([
- ['page',1],
- ['limit',20],
- ['uid',$this->userInfo['uid']],
- ['group',''],
- ]);
- if($where['group'])
- return JsonService::successful(UserSign::getSignLog($where,true));
- else
- return JsonService::successful(UserSign::getSignLog($where));
- }
- /* 2.5.36 修改问题 */
- public function again_order($uni = ''){
- if(!$uni) return JsonService::fail('参数错误!');
- $order = StoreOrder::getUserOrderDetail($this->userInfo['uid'],$uni);
- if(!$order) return JsonService::fail('订单不存在!');
- $order = StoreOrder::tidyOrder($order,true);
- $res = array();
- foreach ($order['cartInfo'] as $v) {
- if($v['combination_id']) return JsonService::fail('拼团产品不能再来一单,请在拼团产品内自行下单!');
- else if($v['bargain_id']) return JsonService::fail('砍价产品不能再来一单,请在砍价产品内自行下单!');
- else $res[] = StoreCart::setCart($this->userInfo['uid'], $v['product_id'], $v['cart_num'], isset($v['productInfo']['attrInfo']['unique']) ? $v['productInfo']['attrInfo']['unique'] : '', 'product', 0, 0);
- }
- $cateId = [];
- foreach ($res as $v){
- if(!$v) return JsonService::fail('再来一单失败,请重新下单!');
- $cateId[] = $v['id'];
- }
- return JsonService::successful('ok',implode(',',$cateId));
- }
- /**
- * 获取用户手机号码
- * @param Request $request
- * @return \think\response\Json
- */
- public function bind_mobile(Request $request){
- $data = UtilService::postMore([['info',[]]],$request);
- $data = $data['info'];
- unset($data['info']);
- //解密获取用户信息
- $data['iv'] = urldecode(urlencode($data['iv']));
- try{
- $userInfo = MiniProgramService::encryptor($data['session_key'], $data['iv'], $data['encryptedData']);
- if(!empty($userInfo['purePhoneNumber'])){
- if(User::edit(['phone'=>$userInfo['purePhoneNumber']],$this->userInfo['uid']))
- return JsonService::success('绑定成功');
- else
- return JsonService::fail('绑定失败');
- }else
- return JsonService::fail('获取手机号失败');
- }catch (\Exception $e){
- return JsonService::fail('error',$e->getMessage());
- }
- }
- /**
- * 刷新数据缓存
- */
- public function refresh_cache(){
- `php think optimize:schema`;
- `php think optimize:autoload`;
- `php think optimize:route`;
- `php think optimize:config`;
- }
- }
|