Base.php 11 KB

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