Base.php 9.2 KB

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