123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- <?php
- namespace app\data\controller\api\auth;
- use app\data\controller\api\Auth;
- use app\data\controller\api\Data;
- use app\data\model\DataCollectionLog;
- use app\data\model\DataPoolTalent;
- use app\data\model\DataRecruitment;
- use app\data\model\DataTeachingKnowledge;
- use app\data\model\DataUserApplyJobInfo;
- use app\data\model\DataUserApplyJobInfoChild;
- use app\data\model\DataUserPurchaseAcceptance;
- use app\data\model\DataUserRebate;
- use app\data\model\DataUserRepair;
- use app\data\model\DataUserRepairOffer;
- use app\data\model\ShopCoordination;
- use app\data\model\ShopCoordinationOffer;
- use app\data\model\ShopCoordinationOfferAmount;
- use app\data\model\ShopOcean;
- use app\data\model\ShopOceanOffer;
- use app\data\model\ShopOceanOfferAmount;
- use app\data\model\ShopProduction;
- use app\data\model\ShopProductionOffer;
- use app\data\model\ShopProductionOfferAmount;
- use app\data\model\ShopPurchase;
- use app\data\model\ShopPurchaseItem;
- use app\data\model\ShopPurchaseOffer;
- use app\data\model\ShopPurchaseOfferAmount;
- use app\data\service\MessageService;
- use think\admin\Storage;
- use think\db\Query;
- use think\exception\HttpResponseException;
- use think\admin\Controller;
- use hg\apidoc\annotation\Title;
- use hg\apidoc\annotation\Method;
- use hg\apidoc\annotation\Param;
- use hg\apidoc\annotation\Header;
- use hg\apidoc\annotation\Returned;
- use think\facade\Db;
- use think\facade\Validate;
- use think\Request;
- /**
- * @Title("个人中心采购订单")
- */
- class UserPurchase extends Auth
- {
- /**
- * @Title("列表")
- * @Method("get")
- * @Param("tab",desc="1采购2生产3外协4海运")
- * @Param("status",desc="1未报价2已报价3已匹配")
- * @Param ("page",desc="第几页")
- * @Param ("limit",desc="每页几条")
- * @Returned ("user_order",desc="我的报价信息")
- */
- public function list(Request $request)
- {
- $user=$this->getUser();
- $this->_vali([
- 'tab.require'=>'tab必须',
- 'status.require'=>'status必须',
- ],'get');
- // $user['id'] = 64;
- $offer=ShopPurchase::getOffer($request['tab']);
- $key=ShopPurchase::getOfferKey($request['tab']);
- $item=ShopPurchase::getItem($request['tab']);
- $offerTable=$offer->getTable();
- $status = $request['status'];
- $offer->where("{$offerTable}.user_id",$user['id']);
- if($request['status']==1){
- //$offer->where('amount','=',0);
- $offer->whereRaw('amount = 0 or amount is NULL');
- }elseif($request['status']==2){
- $offer->where('amount','>',0);
- // if($request['tab']==1){
- // $item->whereNull("offer_id");
- // }
- if ($request['tab']==1){
- $offer->whereExists(
- $item->where("id",Db::raw("{$offerTable}.item_id"))->whereNull('offer_id')->buildSql()
- );
- }
- if ($request['tab']!=1){
- $offer->whereNotExists(
- $item->where("offer_id",Db::raw("{$offerTable}.id"))->buildSql()
- );
- }
- }elseif($request['status']==3){
- $offer->where('amount','>',0);
- $offer->whereExists(
- $item->where("offer_id",Db::raw("{$offerTable}.id"))->buildSql()
- );
- }
- // print_r($offer);
- // exit();
- $offer->group($key);
- $offer->order('id','desc');
- $offer->whereExists(
- ShopPurchase::getQuery($request['tab'])
- ->where(function ($query) use ($status){
- // if($request['tab'] == 1){
- // if($status == 1){
- // $query->whereExists('select * from shop_purchase_item where shop_purchase_item.purchase_id=shop_purchase.id and not exists(select * from shop_purchase_offer where shop_purchase_offer.item_id=shop_purchase_item.id)');
- // }elseif ($status == 2){
- // $query->whereExists('select * from shop_purchase_item where shop_purchase_item.purchase_id=shop_purchase.id and exists(select * from shop_purchase_offer where shop_purchase_offer.item_id=shop_purchase_item.id)');
- // }elseif($status == 3){
- // $query->whereExists('select * from shop_purchase_item where shop_purchase_item.purchase_id=shop_purchase.id and offer_id is not null');
- // }else{
- // $this->error('未知参数');
- // }
- // }else{
- if ($status>2){
- $query->where('status',$status);
- }
- // }
- })
- ->where('id',"{$offerTable}.$key")->buildSql()
- );
- // $list = $offer->select();
- // echo $offer->getLastSql();die;
- $list=$offer->paginate($request['limit']?:15);
- // $this->success('',$list);
- // print_r($item);
- // exit();
- foreach ($list as $k=>$item){
- $with=['items'];
- $order=ShopPurchase::getQuery($request['tab'])->with($with)->find($item[$key]);
- // $this->success('',$order);
- // print_r($item);
- // echo "</br>";
- // exit();
- $order['status']=$request['status'];
- if($request['tab']>1) {
- $order['user_order'] = $order->offers()->where('user_id',$user['id'])->find();
- }
- $list->offsetSet($k,$order);
- }
- $this->success('',$list);
- }
- /**
- * @Title ("列表角标")
- * @Method ("get")
- * @Returned ("user_order",desc="1采购订单2生产订单3外协订单4海外订单5维修订单")
- */
- public function listNum(){
- $user=$this->getUser();
- // $this->_vali([
- // 'tab.require'=>'tab必须',
- // 'status.require'=>'status必须',
- // ],'get');
- $result = [];
- $arr = [1,2,3,4];
- foreach ($arr as $request){
- // $result = 0
- $offer=ShopPurchase::getOffer($request); //ShopPurchaseOffer
- $key=ShopPurchase::getOfferKey($request);
- $item=ShopPurchase::getItem($request);
- $offerTable=$offer->getTable();
- $offer->where("{$offerTable}.user_id",$user['id']); //ShopPurchaseItem
- if($request==1){
- //采购订单
- $offer->where('amount', '>', 0);
- $offer->whereNotExists(
- $item->where("offer_id", Db::raw("{$offerTable}.id"))->buildSql()
- );
- $list = $offer->select();
- // return json($list);
- // $request['tab'] = 1;
- // $request['status'] = 2;
- $offer=ShopPurchase::getOffer(1);
- $key=ShopPurchase::getOfferKey(1);
- $item=ShopPurchase::getItem(1);
- $offerTable=$offer->getTable();
- $status = 2;
- $offer->where("{$offerTable}.user_id",$user['id']);
- // $offer->where('amount','>',0);
- $offer->whereExists(
- $item->where("id",Db::raw("{$offerTable}.item_id"))->whereNull('offer_id')->buildSql()
- );
- $offer->group($key);
- $offer->order('id','desc');
- $list = $offer->paginate(9999);
- $offer->whereExists(
- ShopPurchase::getQuery(1)
- ->where(function ($query) use ($status){
- if ($status>2){
- $query->where('status',$status);
- }
- })
- ->where('id',"{$offerTable}.$key")->buildSql()
- );
- $list = $offer->paginate(9999);
- foreach ($list as $k=>$item){
- $with=['items'];
- $order=ShopPurchase::getQuery(1)->with($with)->find($item[$key]);
- $order['status']=2;
- $list->offsetSet($k,$order);
- }
- // $ids = [];
- // foreach ($list as $k => $v){
- // $ids[] = $v['order_id'];
- // }
- // $ShopPurchase = new ShopPurchase();
- // $lists = $ShopPurchase->where([
- // 'id' => $ids
- // ])->select();
- //$this->success('',$list);
- // $list_1 = $offer->count();
- $result[$request] = $list->count();
- // $result[$request] = $lists->count();
- }elseif($request==2) {
- //$offer->where('amount','>',0);
- // $offer_1=$offer->whereRaw('amount>0 or amount is NULL');
- $offer->whereNotExists(
- $item->where("offer_id",Db::raw("{$offerTable}.id"))->buildSql()
- );
- $offer->group($key);
- $result[$request] = $offer->count();
- }elseif($request==3){
- //$offer->where('amount','>',0);
- $offer->whereNotExists(
- $item->where("offer_id",Db::raw("{$offerTable}.id"))->buildSql()
- );
- $result[$request] = $offer->count();
- }elseif($request==4){
- //$offer->where('amount','>',0);
- $offer->whereNotExists(
- $item->where("offer_id",Db::raw("{$offerTable}.id"))->buildSql()
- );
- $result[$request] = $offer->count();
- }
- $offer->group($key);
- $offer->order('id','desc');
- $list = $offer->select();
- // echo $offer->getLastSql();die;
- }
- $DataUserRepair = new DataUserRepair();
- $DataUserRepairOffer = new DataUserRepairOffer();
- //船老板
- $chuanlaoban_count = $DataUserRepair
- ->where('uuid',$user['id'])
- ->where('status','in','1,2')
- ->where('is_del',1)
- ->count();
- //维修工
- $xiuligong_count = $DataUserRepairOffer::
- hasWhere('repair',function (Query $query){
- $query->where('is_del',1);
- })
- ->with(['repair'=>function($query){
- $query->withoutField('is_del,update_at');
- }])
- ->where('offer_id',$this->uuid)
- // ->where("offer_id",99)
- ->where(function ($query) use ($status){
- $repair_ids = DataUserRepairOffer::mk()
- ->where('offer_id',$this->uuid)
- //->where('price','>',0)
- ->group('repair_id')
- ->column('repair_id');
- switch ($status){
- case 1:
- $query->whereNotIn('repair_id',$repair_ids)->where('is_deal',0)->where('status','in','1,2');
- break;
- case 2:
- $query->whereIn('repair_id',$repair_ids)->where('is_deal',0)->where('status','in','1,2');
- break;
- case 3:
- $query->where('is_deal',1)->where('status',3);
- break;
- }
- })
- //->where('price','>',0)
- ->where('is_deal',0)
- ->where('status','in','1,2')
- ->group('repair_id')
- ->count();
- // echo $xiuligong_count->getLastSql();die;
- $result['weixiu'] = $chuanlaoban_count+$xiuligong_count;
- $result = array_combine(['caigou','shengchan','waixie','haiwai','weixiu'],($result));
- $this->success('',$result);
- }
- }
|