UserPurchase.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?php
  2. namespace app\data\controller\api\auth;
  3. use app\data\controller\api\Auth;
  4. use app\data\controller\api\Data;
  5. use app\data\model\DataCollectionLog;
  6. use app\data\model\DataPoolTalent;
  7. use app\data\model\DataRecruitment;
  8. use app\data\model\DataTeachingKnowledge;
  9. use app\data\model\DataUserApplyJobInfo;
  10. use app\data\model\DataUserApplyJobInfoChild;
  11. use app\data\model\DataUserPurchaseAcceptance;
  12. use app\data\model\DataUserRebate;
  13. use app\data\model\DataUserRepair;
  14. use app\data\model\DataUserRepairOffer;
  15. use app\data\model\ShopCoordination;
  16. use app\data\model\ShopCoordinationOffer;
  17. use app\data\model\ShopCoordinationOfferAmount;
  18. use app\data\model\ShopOcean;
  19. use app\data\model\ShopOceanOffer;
  20. use app\data\model\ShopOceanOfferAmount;
  21. use app\data\model\ShopProduction;
  22. use app\data\model\ShopProductionOffer;
  23. use app\data\model\ShopProductionOfferAmount;
  24. use app\data\model\ShopPurchase;
  25. use app\data\model\ShopPurchaseItem;
  26. use app\data\model\ShopPurchaseOffer;
  27. use app\data\model\ShopPurchaseOfferAmount;
  28. use app\data\service\MessageService;
  29. use think\admin\Storage;
  30. use think\db\Query;
  31. use think\exception\HttpResponseException;
  32. use think\admin\Controller;
  33. use hg\apidoc\annotation\Title;
  34. use hg\apidoc\annotation\Method;
  35. use hg\apidoc\annotation\Param;
  36. use hg\apidoc\annotation\Header;
  37. use hg\apidoc\annotation\Returned;
  38. use think\facade\Db;
  39. use think\facade\Validate;
  40. use think\Request;
  41. /**
  42. * @Title("个人中心采购订单")
  43. */
  44. class UserPurchase extends Auth
  45. {
  46. /**
  47. * @Title("列表")
  48. * @Method("get")
  49. * @Param("tab",desc="1采购2生产3外协4海运")
  50. * @Param("status",desc="1未报价2已报价3已匹配")
  51. * @Param ("page",desc="第几页")
  52. * @Param ("limit",desc="每页几条")
  53. * @Returned ("user_order",desc="我的报价信息")
  54. */
  55. public function list(Request $request)
  56. {
  57. $user=$this->getUser();
  58. $this->_vali([
  59. 'tab.require'=>'tab必须',
  60. 'status.require'=>'status必须',
  61. ],'get');
  62. // $user['id'] = 64;
  63. $offer=ShopPurchase::getOffer($request['tab']);
  64. $key=ShopPurchase::getOfferKey($request['tab']);
  65. $item=ShopPurchase::getItem($request['tab']);
  66. $offerTable=$offer->getTable();
  67. $status = $request['status'];
  68. $offer->where("{$offerTable}.user_id",$user['id']);
  69. if($request['status']==1){
  70. //$offer->where('amount','=',0);
  71. $offer->whereRaw('amount = 0 or amount is NULL');
  72. }elseif($request['status']==2){
  73. $offer->where('amount','>',0);
  74. // if($request['tab']==1){
  75. // $item->whereNull("offer_id");
  76. // }
  77. if ($request['tab']==1){
  78. $offer->whereExists(
  79. $item->where("id",Db::raw("{$offerTable}.item_id"))->whereNull('offer_id')->buildSql()
  80. );
  81. }
  82. if ($request['tab']!=1){
  83. $offer->whereNotExists(
  84. $item->where("offer_id",Db::raw("{$offerTable}.id"))->buildSql()
  85. );
  86. }
  87. }elseif($request['status']==3){
  88. $offer->where('amount','>',0);
  89. $offer->whereExists(
  90. $item->where("offer_id",Db::raw("{$offerTable}.id"))->buildSql()
  91. );
  92. }
  93. // print_r($offer);
  94. // exit();
  95. $offer->group($key);
  96. $offer->order('id','desc');
  97. $offer->whereExists(
  98. ShopPurchase::getQuery($request['tab'])
  99. ->where(function ($query) use ($status){
  100. // if($request['tab'] == 1){
  101. // if($status == 1){
  102. // $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)');
  103. // }elseif ($status == 2){
  104. // $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)');
  105. // }elseif($status == 3){
  106. // $query->whereExists('select * from shop_purchase_item where shop_purchase_item.purchase_id=shop_purchase.id and offer_id is not null');
  107. // }else{
  108. // $this->error('未知参数');
  109. // }
  110. // }else{
  111. if ($status>2){
  112. $query->where('status',$status);
  113. }
  114. // }
  115. })
  116. ->where('id',"{$offerTable}.$key")->buildSql()
  117. );
  118. // $list = $offer->select();
  119. // echo $offer->getLastSql();die;
  120. $list=$offer->paginate($request['limit']?:15);
  121. // $this->success('',$list);
  122. // print_r($item);
  123. // exit();
  124. foreach ($list as $k=>$item){
  125. $with=['items'];
  126. $order=ShopPurchase::getQuery($request['tab'])->with($with)->find($item[$key]);
  127. // $this->success('',$order);
  128. // print_r($item);
  129. // echo "</br>";
  130. // exit();
  131. $order['status']=$request['status'];
  132. if($request['tab']>1) {
  133. $order['user_order'] = $order->offers()->where('user_id',$user['id'])->find();
  134. }
  135. $list->offsetSet($k,$order);
  136. }
  137. $this->success('',$list);
  138. }
  139. /**
  140. * @Title ("列表角标")
  141. * @Method ("get")
  142. * @Returned ("user_order",desc="1采购订单2生产订单3外协订单4海外订单5维修订单")
  143. */
  144. public function listNum(){
  145. $user=$this->getUser();
  146. // $this->_vali([
  147. // 'tab.require'=>'tab必须',
  148. // 'status.require'=>'status必须',
  149. // ],'get');
  150. $result = [];
  151. $arr = [1,2,3,4];
  152. foreach ($arr as $request){
  153. // $result = 0
  154. $offer=ShopPurchase::getOffer($request); //ShopPurchaseOffer
  155. $key=ShopPurchase::getOfferKey($request);
  156. $item=ShopPurchase::getItem($request);
  157. $offerTable=$offer->getTable();
  158. $offer->where("{$offerTable}.user_id",$user['id']); //ShopPurchaseItem
  159. if($request==1){
  160. //采购订单
  161. $offer->where('amount', '>', 0);
  162. $offer->whereNotExists(
  163. $item->where("offer_id", Db::raw("{$offerTable}.id"))->buildSql()
  164. );
  165. $list = $offer->select();
  166. // return json($list);
  167. // $request['tab'] = 1;
  168. // $request['status'] = 2;
  169. $offer=ShopPurchase::getOffer(1);
  170. $key=ShopPurchase::getOfferKey(1);
  171. $item=ShopPurchase::getItem(1);
  172. $offerTable=$offer->getTable();
  173. $status = 2;
  174. $offer->where("{$offerTable}.user_id",$user['id']);
  175. // $offer->where('amount','>',0);
  176. $offer->whereExists(
  177. $item->where("id",Db::raw("{$offerTable}.item_id"))->whereNull('offer_id')->buildSql()
  178. );
  179. $offer->group($key);
  180. $offer->order('id','desc');
  181. $list = $offer->paginate(9999);
  182. $offer->whereExists(
  183. ShopPurchase::getQuery(1)
  184. ->where(function ($query) use ($status){
  185. if ($status>2){
  186. $query->where('status',$status);
  187. }
  188. })
  189. ->where('id',"{$offerTable}.$key")->buildSql()
  190. );
  191. $list = $offer->paginate(9999);
  192. foreach ($list as $k=>$item){
  193. $with=['items'];
  194. $order=ShopPurchase::getQuery(1)->with($with)->find($item[$key]);
  195. $order['status']=2;
  196. $list->offsetSet($k,$order);
  197. }
  198. // $ids = [];
  199. // foreach ($list as $k => $v){
  200. // $ids[] = $v['order_id'];
  201. // }
  202. // $ShopPurchase = new ShopPurchase();
  203. // $lists = $ShopPurchase->where([
  204. // 'id' => $ids
  205. // ])->select();
  206. //$this->success('',$list);
  207. // $list_1 = $offer->count();
  208. $result[$request] = $list->count();
  209. // $result[$request] = $lists->count();
  210. }elseif($request==2) {
  211. //$offer->where('amount','>',0);
  212. // $offer_1=$offer->whereRaw('amount>0 or amount is NULL');
  213. $offer->whereNotExists(
  214. $item->where("offer_id",Db::raw("{$offerTable}.id"))->buildSql()
  215. );
  216. $offer->group($key);
  217. $result[$request] = $offer->count();
  218. }elseif($request==3){
  219. //$offer->where('amount','>',0);
  220. $offer->whereNotExists(
  221. $item->where("offer_id",Db::raw("{$offerTable}.id"))->buildSql()
  222. );
  223. $result[$request] = $offer->count();
  224. }elseif($request==4){
  225. //$offer->where('amount','>',0);
  226. $offer->whereNotExists(
  227. $item->where("offer_id",Db::raw("{$offerTable}.id"))->buildSql()
  228. );
  229. $result[$request] = $offer->count();
  230. }
  231. $offer->group($key);
  232. $offer->order('id','desc');
  233. $list = $offer->select();
  234. // echo $offer->getLastSql();die;
  235. }
  236. $DataUserRepair = new DataUserRepair();
  237. $DataUserRepairOffer = new DataUserRepairOffer();
  238. //船老板
  239. $chuanlaoban_count = $DataUserRepair
  240. ->where('uuid',$user['id'])
  241. ->where('status','in','1,2')
  242. ->where('is_del',1)
  243. ->count();
  244. //维修工
  245. $xiuligong_count = $DataUserRepairOffer::
  246. hasWhere('repair',function (Query $query){
  247. $query->where('is_del',1);
  248. })
  249. ->with(['repair'=>function($query){
  250. $query->withoutField('is_del,update_at');
  251. }])
  252. ->where('offer_id',$this->uuid)
  253. // ->where("offer_id",99)
  254. ->where(function ($query) use ($status){
  255. $repair_ids = DataUserRepairOffer::mk()
  256. ->where('offer_id',$this->uuid)
  257. //->where('price','>',0)
  258. ->group('repair_id')
  259. ->column('repair_id');
  260. switch ($status){
  261. case 1:
  262. $query->whereNotIn('repair_id',$repair_ids)->where('is_deal',0)->where('status','in','1,2');
  263. break;
  264. case 2:
  265. $query->whereIn('repair_id',$repair_ids)->where('is_deal',0)->where('status','in','1,2');
  266. break;
  267. case 3:
  268. $query->where('is_deal',1)->where('status',3);
  269. break;
  270. }
  271. })
  272. //->where('price','>',0)
  273. ->where('is_deal',0)
  274. ->where('status','in','1,2')
  275. ->group('repair_id')
  276. ->count();
  277. // echo $xiuligong_count->getLastSql();die;
  278. $result['weixiu'] = $chuanlaoban_count+$xiuligong_count;
  279. $result = array_combine(['caigou','shengchan','waixie','haiwai','weixiu'],($result));
  280. $this->success('',$result);
  281. }
  282. }