Base.php 12 KB

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