Proorder.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ProcessWait;
  4. use think\App;
  5. use think\facade\Db;
  6. //消息(已读未读)
  7. class Proorder extends Base
  8. {
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. }
  13. //已读列表
  14. public function list()
  15. {
  16. /**暂时屏蔽
  17. * $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']) :"1";
  18. * $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']) :"10";
  19. * $where =[['is_del',"=",0],['a.order_status',"=",2]];
  20. * $role=$this->checkRole();
  21. * if(!empty($role['write'])){
  22. * $where[]=["a.action_uid","in",$role['write']];
  23. * }
  24. * $count = Db::name('process_order')->alias("a")->leftJoin("workflow b","a.order_id=b.order_id and a.order_code=b.order_code")->where($where)->count();
  25. * $total = ceil("$count/$size");
  26. * $page = $page>$total ? $total:$page;
  27. * $list = Db::name('process_order')->alias("a")->leftJoin("workflow b","a.order_id=b.order_id and a.order_code=b.order_code")
  28. * ->field("b.apply_id,b.apply_name,a.addtime,a.action_uid,a.action_name,a.order_status,a.action_status,a.order_type,a.action_process,a.order_code,a.order_id,a.id")
  29. * ->where($where)->page($page,$size)->order("a.addtime desc")->select();
  30. * $data=[];
  31. * foreach ($list as $value){
  32. * $str = Db::name("process")->where(['process_type' => $value['order_type']])->field("process_name,status")->find();
  33. * $var = Db::name("action_process")->where(['order_type'=>$value['order_type'],'order_process'=>$value['action_status']])->field("status_name,order_process,order_name,roleid")->find();
  34. * $value['process_name']=$str['process_name'];
  35. * $value['order_name']=$var['order_name'];
  36. * $value['status_name'] = $var['status_name'];
  37. * $data[]=$value;
  38. * }
  39. * return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  40. * **/
  41. {
  42. $param = $this->request->filter('trim')->only(['token', 'apply_id' => '', 'action_uid' => '', 'order_code' => '', 'page' => 1, 'size' => 10], 'post');
  43. $db = ProcessWait::alias("a")
  44. ->leftJoin('workflow b', 'a.order_type=b.order_type and a.order_id=b.order_id')//这个地方不适宜用order_code,因为特殊单子没有编码,例如离职交接单
  45. ->where(['is_del' => 0, 'a.status' => ProcessWait::$status_finish]);
  46. $db->where(function ($query) use ($param) {
  47. //所属角色
  48. $role = $this->checkRole();
  49. // if (!empty($role['write']) || $role['roleid'] == 33) $query->whereFindInSet('roleid', $role['roleid']);
  50. $query->whereFindInSet('roleid', $role['roleid']);
  51. //本人id
  52. // $user = GetUserInfo($param['token']);
  53. //if (isset($user['data']['id']))
  54. $query->whereOr('wait_id', $this->uid);
  55. });
  56. if ($param['order_code'] != '') $db->whereLike("a.order_code", '%' . $param['order_code'] . '%');
  57. if ($param['action_uid'] != '') $db->where('a.action_uid', $param['action_uid']);
  58. $count = $db
  59. // ->field("ANY_VALUE(`a`.`id`) id,`a`.order_type,`a`.order_id,GROUP_CONCAT(`a`.`id` ORDER BY `a`.`id` DESC) ids")
  60. ->group('a.order_type,a.order_id')
  61. // ->order(['a.id'=>'desc'])
  62. // ->fetchSql()
  63. // ->withAttr('ids', function ($val) {
  64. // $temp = explode(',', $val);
  65. // return $temp[0];
  66. // })
  67. // ->page($page, $param['size'])
  68. ->count('a.id');
  69. $total = ceil($count / $param['size']);
  70. $page = $param['page'] > $total ? $total : $param['page'];
  71. //筛选符合条件的order_type,排除重复数据
  72. $order_types = $db
  73. ->field("ANY_VALUE(`a`.`id`) id,`a`.order_type,`a`.order_id,GROUP_CONCAT(`a`.`id` ORDER BY `a`.`id` DESC) ids")
  74. ->group('a.order_type,a.order_id')
  75. ->order(['id' => 'desc'])
  76. ->withAttr('ids', function ($val) {
  77. $temp = explode(',', $val);
  78. return $temp[0];
  79. })
  80. ->page($page, $param['size'])
  81. ->select()
  82. ->toArray();
  83. $list = ProcessWait::alias("a")
  84. ->field([
  85. 'b.apply_id',
  86. 'b.apply_name',
  87. 'a.addtime',
  88. 'a.action_uid_finally' => 'action_uid',//取实时操作人id
  89. 'a.action_name_finally' => 'action_name',//取实时操作人
  90. 'a.order_status',
  91. 'a.order_type',
  92. 'a.order_code',
  93. 'a.order_id',
  94. 'a.id',
  95. 'a.order_process_finally' => 'order_process',//取实时状态值
  96. ])
  97. ->whereIn('a.id', array_column($order_types, 'ids'))
  98. ->leftJoin("workflow b", "a.order_type=b.order_type and a.order_id=b.order_id")
  99. // ->page($page, $param['size'])
  100. ->order("a.addtime desc")
  101. ->select()
  102. ->toArray();
  103. //所有流程名称
  104. $all_process = Db::name("process")
  105. ->whereIn('process_type', array_column($list, 'order_type'))
  106. ->column("process_name", 'process_type');
  107. $data = [];
  108. foreach ($list as $value) {
  109. $var = Db::name("action_process")
  110. ->where(['order_type' => $value['order_type'], 'order_process' => $value['order_process']])
  111. // ->whereIn('order_process', [$value['order_process'], $value['order_process_finally']])
  112. ->field("status_name,order_process,order_name,roleid")
  113. // ->column('status_name,order_process,order_name,roleid', 'order_process');
  114. ->findOrEmpty();
  115. $value['process_name'] = isset($all_process[$value['order_type']]) ? $all_process[$value['order_type']] : '';
  116. $value['order_name'] = $var['order_name'];
  117. $value['status_name'] = $var['status_name'];
  118. // $value['order_process_finally_status_name'] = $var[$value['order_process_finally']]['status_name'] ?? '';
  119. $data[] = $value;
  120. }
  121. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  122. }
  123. }
  124. //待处理列表
  125. public function waitlist()
  126. {
  127. $param = $this->request->filter('trim')->only(['token', 'apply_id' => '', 'action_uid' => '', 'order_code' => '', 'page' => 1, 'size' => 10], 'post');
  128. $db = ProcessWait::alias("a")
  129. ->leftJoin('workflow b', 'a.order_type=b.order_type and a.order_id=b.order_id')//这个地方不适宜用order_code,因为特殊单子没有编码,例如离职交接单
  130. // ->leftJoin('process p', 'p.process_type=a.order_type AND p.is_del=0 AND p.status=1')
  131. ->where(['a.status' => ProcessWait::$status_wait]);
  132. // $db->where(function ($query) use ($param) {
  133. //所属角色
  134. $role = $this->checkRole();
  135. if ($role['roleid'] != 1) $db->whereFindInSet('handle_user_list', $this->uid);
  136. // if (!empty($role['write']) || $role['roleid'] == 33) $query->whereFindInSet('roleid', $role['roleid']);
  137. // $query->whereFindInSet('roleid', $role['roleid']);
  138. //本人id
  139. // $query->whereOr('wait_id', $this->uid);
  140. // });
  141. if ($param['order_code'] != '') $db->whereLike('a.order_code', '%' . $param['order_code'] . '%');
  142. if ($param['action_uid'] != '') $db->where('a.action_uid', $param['action_uid']);
  143. $count = $db->count();
  144. $total = ceil($count / $param['size']);
  145. $page = $param['page'] > $total ? $total : $param['page'];
  146. $list = $db
  147. ->field("a.id,a.addtime,a.action_name,a.order_status,a.order_type,a.order_process,a.order_code,a.order_id,a.handle_user_list,b. apply_id,b.apply_name")
  148. ->page($page, $param['size'])
  149. ->order("a.addtime desc")
  150. // ->append(['handle_user_list'])
  151. // ->withAttr('handle_user_list', function ($val, $da) {
  152. // return [];
  153. // })
  154. ->select()
  155. ->toArray();
  156. //所有流程名称
  157. $all_process = Db::name("process")
  158. ->whereIn('process_type', array_column($list, 'order_type'))
  159. ->column("process_name", 'process_type');
  160. $data = [];
  161. foreach ($list as $value) {
  162. $var = Db::name("action_process")
  163. ->where(['order_type' => $value['order_type'], 'order_process' => $value['order_process']])
  164. ->field("status_name,order_process,order_name,roleid")
  165. ->find();
  166. $value['process_name'] = isset($all_process[$value['order_type']]) ? $all_process[$value['order_type']] : '';
  167. $value['order_name'] = $var['order_name'];
  168. $value['status_name'] = $var['status_name'];
  169. //找到流程对应记录的所有人(创建人 or 申请人 or 采购员)
  170. // $holder_id = 0;
  171. // switch ($value['order_type']) {
  172. // //1.采购单流程
  173. // case 'CGD':
  174. // $holder_id = Db::name('purchease_order')->where(['id' => $value['order_id'], 'is_del' => 0])->value('cgder_id', 0);
  175. // break;
  176. // //2.采购单入库流程
  177. // case 'RKD':
  178. // $holder_id = Db::name('purchease_in')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
  179. // break;
  180. // //3.备货申请单流程
  181. // case 'BHD':
  182. // $holder_id = Db::name('purchease')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
  183. // break;
  184. // //4.销售订单流程
  185. // case 'XSQRD':
  186. // $holder_id = Db::name('sale')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
  187. // break;
  188. // //5.发货申请单流程
  189. // case 'CKD':
  190. // $holder_id = Db::name('order_out')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
  191. // break;
  192. // //6.售后申请单流程
  193. // case 'SHD':
  194. // $holder_id = Db::name('order_return')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
  195. // break;
  196. // //7.售后退货单流程
  197. // case 'CKTHD':
  198. // $holder_id = Db::name('order_back')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
  199. // break;
  200. // //8.销售退货单流程
  201. // case 'XSTHD':
  202. // $holder_id = Db::name('sale_return')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
  203. // break;
  204. // //9.采购工差单流程
  205. // case 'CGGCD':
  206. // $holder_id = Db::name('purchease_diff')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
  207. // break;
  208. // //10.销售工差单流程
  209. // case 'XSGCD':
  210. // $holder_id = Db::name('sale_diff')
  211. // ->alias('a')
  212. // ->where(['a.id' => $value['order_id']])
  213. // ->leftJoin('sale s', 's.orderCode=a.orderCode')
  214. // ->value('s.apply_id', 0);
  215. // break;
  216. // //11.调拨单流程
  217. // case 'DBD':
  218. // $holder_id = Db::name('allot_stock')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
  219. // break;
  220. // //12.盘点单流程
  221. // case 'PDD':
  222. // $holder_id = Db::name('good_check')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
  223. // break;
  224. // //13.议价单流程
  225. // case 'YJD':
  226. // $holder_id = Db::name('bargain_order')->where(['id' => $value['order_id'], 'is_del' => 0])->value('createrid', 0);
  227. // break;
  228. // //14.项目单流程
  229. // case 'PRO':
  230. // $holder_id = Db::name('project')->where(['id' => $value['order_id'], 'is_del' => 0])->value('createrid', 0);
  231. // break;
  232. // //15.商品成本流程
  233. // case 'SPCB':
  234. // $holder_id = Db::name('good_basic')->where(['id' => $value['order_id'], 'is_del' => 0])->value('chargerid', 0);
  235. // break;
  236. // //16.商品上线流程
  237. // case 'SPSX':
  238. // $holder_id = Db::name('good_platform')
  239. // ->alias('a')
  240. // ->where(['a.id' => $value['order_id']])
  241. // ->leftJoin('good g', 'g.spuCode=a.spuCode')
  242. // ->value('g.createrid', 0);
  243. // break;
  244. // //17.活动流程
  245. // case 'HD':
  246. // $holder_id = Db::name('good_activity')->where(['id' => $value['order_id'], 'is_del' => 0])->value('createrid', 0);
  247. // break;
  248. // //19.有赞商品上架流程
  249. // case 'YZSX':
  250. // $holder_id = Db::name('platform_youzan')
  251. // ->alias('a')
  252. // ->where(['a.id' => $value['order_id']])
  253. // ->leftJoin('good g', 'g.spuCode=a.spuCode')
  254. // ->value('g.createrid', 0);
  255. // break;
  256. // //20.有赞订单审核流程
  257. //// case 'YZQRD':
  258. //// $holder_id = Db::name('')->where(['id' => $value['order_id'], 'is_del' => 0])->value('', 0);
  259. //// break;
  260. // //22.离职交接流程
  261. // case 'LZJJ':
  262. // $holder_id = Db::name('resign_info')->where(['id' => $value['order_id'], 'is_del' => 0])->value('hand_uid', 0);
  263. // break;
  264. // //23.采购单退货流程
  265. // case 'CGTHD':
  266. // $holder_id = Db::name('purchease_return')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
  267. // break;
  268. // //24.竞价单流程
  269. // case 'ZXD':
  270. // $holder_id = Db::name('consult_order')->where(['id' => $value['order_id'], 'is_del' => 0])->value('createrid', 0);
  271. // break;
  272. // //25.商品下线流程
  273. // case 'GOL':
  274. // $holder_id = Db::name('good_offline_log')->where(['id' => $value['order_id'], 'is_del' => 0])->value('createrid', 0);
  275. // break;
  276. // }
  277. //根据记录的所有人判断哪些人能看到它的记录
  278. // $uids_1 = $this->get_uids_by_group_share($holder_id, $value['api_url']);
  279. //根据角色筛选
  280. $uid = Db::name('user_role')
  281. ->field('uid')
  282. ->where([
  283. ['is_del', '=', 0],
  284. ['uid', 'in', $value['handle_user_list']],
  285. // ['roleid', '<>', 1],//超级管理员不在这个范围内
  286. ['status', '=', 1],
  287. ])
  288. ->buildSql();
  289. $value['handle_user_list'] = Db::name('depart_user')
  290. ->where(['is_del' => 0, 'status' => 1])
  291. ->where('uid IN ' . $uid)
  292. ->column('nickname');
  293. // $value['uid_1'] = $uids_1;
  294. // $value['uid_2'] = $uids_2;
  295. // $uids = array_intersect($uids_1, $uids_2);
  296. // $users = Db::name('depart_user')->where(['is_del' => 0, 'status' => 1])->whereIn('uid', $uids)->column('nickname');
  297. //当前操作人
  298. // $value['handle_user_list'] = $value['wait_name'] ? array_merge($users, [$value['wait_name']]) : $users;
  299. $data[] = $value;
  300. }
  301. return app_show(0, "获取成功", ["list" => $data, 'count' => $count]);
  302. }
  303. public function all()
  304. {
  305. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  306. if ($token == "") {
  307. return error_show(101, 'token不能为空');
  308. }
  309. $effetc = VerifyTokens($token);
  310. if (!empty($effetc) && $effetc['code'] != 0) {
  311. return error_show($effetc['code'], $effetc['message']);
  312. }
  313. $where = [["is_del", "=", 0]];
  314. $process_name = isset($this->post['process_name']) && $this->post['process_name'] !== "" ? trim($this->post['process_name']) : "";
  315. if ($process_name != "") {
  316. $where[] = ["process_name", "like", "%$process_name%"];
  317. }
  318. $process_type = isset($this->post['process_type']) && $this->post['process_type'] !== "" ? trim($this->post['process_type']) : "";
  319. if ($process_type != "") {
  320. $where[] = ["process_type", "like", "%$process_type%"];
  321. }
  322. $list = Db::name('process')->where($where)->order("addtime desc")->select();
  323. return app_show(0, "获取成功", $list);
  324. }
  325. }