Base.php 13 KB

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