Base.php 12 KB

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