Base.php 11 KB

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