Base.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. class Base extends \app\BaseController
  8. {
  9. public $post=[];
  10. public $uid='';
  11. public $uname='';
  12. public $roleid='';
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->post =$this->request->post();
  17. $this->validateToken();
  18. }
  19. public function validateToken()
  20. {
  21. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  22. if($token==""){
  23. return error_show(101,'token不能为空');
  24. }
  25. $effetc = VerifyTokens($token);
  26. if(!empty($effetc) && $effetc['code']!=0) {
  27. return error_show($effetc['code'], $effetc['message']);
  28. }
  29. $this->uid=isset($effetc['data']['user']['id']) ?$effetc['data']['user']['id']:"";
  30. $this->uname=isset($effetc['data']['user']['nickname']) ?$effetc['data']['user']['nickname']:"";
  31. $uid = Db::name("user_role")->where(['uid'=>$this->uid,"is_del"=>0,"status"=>1])->find();
  32. if($uid==false || $uid['status']==0){
  33. return error_show(102,'账户已禁用');
  34. }
  35. }
  36. public function checkRole(){
  37. $uid = Db::name("user_role")->where(['uid'=>$this->uid,"is_del"=>0,"status"=>1])->find();
  38. if($uid==false){
  39. return [];
  40. }
  41. $action=[];
  42. $this->roleid=$uid['roleid'];
  43. $role =Db::name("role_action")->where(["role_id"=>$uid['roleid'],"status"=>1])->find();
  44. $action['action_conllect']=isset($role['action_conllect'])? $role['action_conllect']:'';
  45. $action['write'][]=$this->uid;
  46. $group=[];
  47. $group = Db::name("role_group")->where("FIND_IN_SET($this->uid,group_user) > 0")->column("id");
  48. $where="to_user=$this->uid";
  49. if(!empty($group)){
  50. $where.=" or to_group in (".implode(",",$group).")";
  51. }
  52. $paltform = Db::name("user_platform")->where(["uid"=>$this->uid,"is_del"=>0])->find();
  53. $action['platform']= $paltform!=false ? explode(",",$paltform['platform']) :[];
  54. $share =Db::name("role_share")->where(["is_del"=>0,"status"=>1])->where($where) ->select();
  55. if(!empty($share)){
  56. foreach ($share as $value){
  57. if($value['action']==1){
  58. if($value['share_user']!=""){
  59. $action['write'][]=$value['share_user'];
  60. $user=Db::name("user_role")->where(['uid'=>$value['share_user'],"is_del"=>0,"status"=>1])->find();
  61. if($user!=false){
  62. $role =Db::name("role_action")->where(["role_id"=>$user['roleid'],"status"=>1])->find();
  63. if($role!=false){
  64. $conlect =Db::name("action")->where(['menuid'=>explode(",",$value['action_collect'])])->column("id");
  65. $shar=explode(",",$value['action_collect']);
  66. $wish =array_intersect($conlect,$shar);
  67. $action['action_conllect'].=empty($wish)?"":",".implode(",",$wish);
  68. }
  69. }
  70. }
  71. }
  72. if($value['action']===0){
  73. if($value['share_user']!="") $action['write'][]=$value['share_user'];
  74. if($value['action_collect']!=''){
  75. $act =Db::name("action")->where(['menuid'=>explode(",",$value['action_collect']),"action_code"=>'001'])->column("id");
  76. $action['action_conllect'].=empty($act)?"":",".implode(",",$act);
  77. }
  78. }
  79. if($value['action']===''){
  80. if($value['share_user']!="") $action['write'][]=$value['share_user'];
  81. if($value['action_collect']!=''){
  82. $act =Db::name("action")->where(['menuid'=>explode(",",$value['action_collect']),"action_code"=>'001'])->column("id");
  83. $action['action_conllect'].=empty($act)?"":",".implode(",",$act);
  84. }
  85. }
  86. }
  87. }
  88. /**
  89. * 离职交接权限
  90. */
  91. $resgin= Db::name("resign_info")->where([["hand_uid","=",$this->uid],["is_del","=",0],['status',"=",4]])
  92. ->column(['resign_uid']);
  93. if(!empty($resgin)){
  94. $action['write']= array_unique(array_merge($action['write'],$resgin));
  95. }
  96. /**
  97. * 超级管理员看到所有人的数据
  98. */
  99. if($uid['roleid']==1 || $uid['roleid']==33){
  100. $action['write']=[];
  101. }
  102. $action['roleid']=$uid['roleid'];
  103. $action['action_conllect']=implode(",",array_unique(explode(",",$action['action_conllect'])));
  104. return $action;
  105. }
  106. /**
  107. * @param $good
  108. * @param $isZx
  109. * @param string $thNo
  110. * @return mixed|string
  111. * @throws \think\Exception
  112. */
  113. public function CheckGood($good,$isZx,$thNo=''){
  114. $spuCode= makeNo("SKU");
  115. //查询是否存在转库存品记录 存在则返回库存编号
  116. $newCode= Db::name("good_change_log")->where(["oldCode"=>$good['spuCode']])->value("newCode",'');
  117. if($newCode==''){
  118. $log=["oldCode"=>$good['spuCode'],
  119. "order_source"=>$isZx,
  120. "newCode"=>$spuCode,
  121. "thCode"=>$thNo,
  122. "createrid"=>$this->uid,
  123. "creater"=>$this->uname,
  124. "addtime"=>date("Y-m-d H:i:s")
  125. ];
  126. }else{
  127. return $newCode;
  128. }
  129. if($isZx==1){
  130. $supplier =Db::name("supplier")->where(["code"=>$good['supplierNo']])->findOrEmpty();
  131. if(empty($supplier)) throw new \Exception('非库存商品转库存失败');
  132. $good = [
  133. 'spuCode' => $spuCode,
  134. 'good_code' => $good['good_code'],
  135. 'good_name' => $good['good_name'],
  136. 'cat_id' => $good['cat_id'],
  137. 'brand_id' => $good['brand_id'],
  138. 'companyNo' => $good['companyNo'],
  139. 'good_unit' => $good['good_unit'],
  140. 'good_type' => $good['good_type'],
  141. 'moq' => $good['moq'],
  142. 'customized' => $good['customized'],
  143. 'tax' => $good['tax'],
  144. 'supplierNo' => $good['supplierNo'],
  145. 'is_auth' => $good['is_auth'],
  146. 'auth_img' => $good['auth_img'],
  147. 'after_sales' => '',
  148. 'craft_desc' => $good['craft_desc'],
  149. 'good_remark' => $good['good_remark'],
  150. 'weight' => $good['weight'],
  151. 'packing_way' => '',
  152. 'packing_size' => '',
  153. 'packing_spec' => '',
  154. 'packing_list' => '',
  155. 'packing_weight' => '',
  156. 'good_bar' => '',
  157. 'supply_area' => $good['supply_area'],
  158. 'delivery_place' => '',
  159. 'origin_place' => '',
  160. 'delivery_day' => '',
  161. 'lead_time' => '',
  162. 'sample_day' => '',
  163. 'sample_fee' => '',
  164. 'good_img' => '',//$good['good_img'],
  165. 'good_thumb_img' => $good['good_thumb_img'],
  166. 'good_info_img' => $good['good_img'],//商品主图对应到商品详情
  167. 'cert_fee' => '',
  168. 'packing_fee' => '',
  169. 'cost_fee' => '',
  170. 'mark_fee' => '',
  171. 'demo_fee' => '',
  172. 'open_fee' => '',
  173. 'noble_metal' => $good['noble_metal'],
  174. 'noble_weight' => $good['good_weight'],
  175. 'is_gold_price' => $good['is_gold_price'],
  176. 'cgd_gold_price' => '',
  177. 'market_price' => '',
  178. 'nake_price' => '',
  179. 'is_step' => '',
  180. 'is_online' => '0',
  181. 'status' =>7,//咨询商品待编辑
  182. 'createrid' =>$good['createrid'],
  183. 'creater' => $good['creater'],
  184. 'field_change' => '',
  185. 'is_del' => 0,
  186. 'is_support_stock' => 0,
  187. 'addtime' => date('Y-m-d H:i:s'),
  188. 'updatetime' => date('Y-m-d H:i:s'),
  189. 'is_diff' => $good['is_diff'],
  190. 'config' => $good['config'],
  191. 'other_config' => $good['other_config'],
  192. 'chargerid'=>$supplier['personid']??$good['createrid'],
  193. 'charger'=>$supplier['person']??$good['creater'],//负责人跟创建人一致
  194. ];
  195. }else{
  196. $good['id']=null;
  197. $good['spuCode']=$spuCode;
  198. $good['is_stock']=1;
  199. $good['is_support_stock']=0;
  200. $good['status']=7;
  201. $good['addtime']=date("Y-m-d H:i:s");
  202. $good['updatetime']=date("Y-m-d H:i:s");
  203. }
  204. $insert =Db::name("good_basic")->insert($good,true);
  205. if($insert==false) throw new \Exception("非库存商品转库存失败",1005);
  206. //修改状态,添加待办
  207. ActionLog::logAdd($this->post['token'], [
  208. "order_code" =>$newCode,//咨询单详情编号
  209. "status" => 0,//这里的status是之前的值
  210. "action_remark" => '非库存品退货转库存',//备注
  211. "action_type" => "create"//新建create,编辑edit,更改状态status
  212. ], "SPCB", 7,$good);
  213. ProcessOrder::AddProcess($this->post['token'], [
  214. "order_type" => 'SPCB',
  215. "order_code" =>$newCode,//咨询单详情编号
  216. "order_id" => $insert,
  217. "order_status" =>7,
  218. "before_status"=>0,
  219. 'holder_id'=>$good['createrid'],
  220. ]);
  221. $newAdd=Db::name("good_change_log")->insert($log);
  222. if($newAdd==false) throw new \Exception("非库存商品转库存失败",1005);
  223. return $spuCode;
  224. }
  225. }