AboutPlater.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <?php
  2. defined('ONLY_ONLY_ONLY') or exit('Access Denied');
  3. /*****************平台方相关如角色权限等******************/
  4. function bizPlater_getFELoginInfo($includePwd = false)
  5. {
  6. $subSystem = intval(SUBSYS_PLAT_PCWEB);
  7. $GPC = input_param_handle(false);
  8. $ajaxdata = input_getPostObj();
  9. $loginName = isset($ajaxdata["loginName"]) ? $ajaxdata["loginName"] : $GPC["loginName"];
  10. if (empty($loginName)) {
  11. throw new GeneralException("", "没有传递必要的loginName参数,或者登录名为空!");
  12. }
  13. if (mb_strlen(trim($loginName)) < 2) {
  14. throw new GeneralException("", "登录名不能为空且长度至少2位!");
  15. }
  16. if ($includePwd) {
  17. $loginPwd = isset($ajaxdata["loginPwd"]) ? $ajaxdata["loginPwd"] : $GPC["loginPwd"];
  18. if (empty($loginPwd)) {
  19. throw new GeneralException("", "没有传递必要的loginPwd参数,或密码为空!");
  20. }
  21. if (mb_strlen(trim($loginPwd)) <= 3) {
  22. throw new GeneralException("", "登录密码不能为空且长度至少3位!");
  23. }
  24. }
  25. return array("loginName" => $loginName, "loginPwd" => $loginPwd);
  26. }
  27. function bizPlater_cryptLoginPwd($loginPwd)
  28. {
  29. return md5(md5($loginPwd));
  30. }
  31. function bizPlater_verifyToken()
  32. {
  33. $GPC = input_param_handle(false);
  34. $ajaxdata = input_getPostObj();
  35. $loginName = isset($ajaxdata["loginName"]) ? $ajaxdata["loginName"] : $GPC["loginName"];
  36. if (empty($loginName)) {
  37. throw new GeneralException("", "没有传递必要的loginName参数,或者登录名为空!");
  38. }
  39. $subSystem = intval(SUBSYS_PLAT_PCWEB);
  40. $loginInfo = bizPlater_getFELoginInfo(false);
  41. $loginName = $loginInfo["loginName"];
  42. $baseUser = pdo_fetch("select * from base_user where deleted=0 and subsystem=:subsystem and `login_name`=:login_name limit 1;", array(
  43. ":subsystem" => intval($subSystem),
  44. ":login_name" => trim($loginName),
  45. ));
  46. if (empty($baseUser)) {
  47. throw new GeneralException("", "没有定位到此登录名的用户记录,请确认输入是否正确!");
  48. }
  49. base_verifyForendToken($baseUser); //前端会话TOKEN校验
  50. return array("baseUser" => $baseUser);
  51. }
  52. //获取当前用户所赋予的角色列表
  53. function bizPlater_getRoleSet($bizPlater)
  54. {
  55. $subSystem = intval(SUBSYS_PLAT_PCWEB);
  56. $roleList = pdo_fetchall("select r.* from base_roleuser ru
  57. left join base_role r on r.id=ru.roleid
  58. where ru.`userid`=:userid and r.subsystem=:subsystem and r.deleted=0;", array(
  59. ":userid" => intval($bizPlater["id"]),
  60. ":subsystem" => intval($subSystem),
  61. ));
  62. if (empty($roleList)) {
  63. throw new GeneralException("", "此用户没有被赋予任何角色,请联系平台超级管理员!");
  64. }
  65. return $roleList;
  66. }
  67. //获取当前用户所属角色下可用的页面模块列表
  68. function bizPlater_getModuleSet($bizPlater)
  69. {
  70. $subSystem = intval(SUBSYS_PLAT_PCWEB);
  71. $roleList = bizPlater_getRoleSet($bizPlater); //先确定当前用户有角色身份
  72. $moduleList = pdo_fetchall("select * from base_permission_object where `subsystem`=:subsystem and deleted=0
  73. order by `parentid` asc,`ranksn` asc;", array(":subsystem" => intval($subSystem)));
  74. if (empty($moduleList)) {
  75. throw new GeneralException("", "竟然没有配置任何模块,请联系平台超级管理员!");
  76. }
  77. $tmpModuleSet = array();
  78. foreach ($moduleList as $module) {
  79. $module["AAA_allowed"] = false; //默认都不可用,将来可根据模块本身的配置进行预设
  80. $tmpModuleSet[$module["id"]] = $module;
  81. }
  82. foreach ($roleList as $role) {
  83. if (trim($role["role_code"]) == "SuperAdmin") { //超管一票允许
  84. foreach ($tmpModuleSet as $key => &$moduleA) {
  85. $moduleA["AAA_allowed"] = true;
  86. }
  87. break;
  88. }
  89. $roleModIdSet = pdo_fetchall("select bpo.id as id from base_role_permission brp
  90. left join base_permission_object bpo on bpo.id=brp.objectid
  91. where bpo.deleted=0 and brp.`roleid`=:roleid and brp.`permission_run`='1' and bpo.id>0;", array(":roleid" => $role["id"]));
  92. foreach ($roleModIdSet as $roleModuleId) {
  93. $tmpModuleSet[$roleModuleId["id"]]["AAA_allowed"] = true;
  94. }
  95. }
  96. $forendSet = array(
  97. "navIcon" => array(),
  98. "states" => array(),
  99. "mainRoleName" => $roleList[0]["role_name"],
  100. "undoList" => bizPlater_undoList(),
  101. );
  102. $orderSN = 0;
  103. foreach ($tmpModuleSet as $key => $moduleB) {
  104. if ($moduleB["AAA_allowed"] == true && intval($moduleB["parentid"]) == 0) {
  105. array_push($forendSet["navIcon"], array(
  106. "id_id" => $moduleB["id"],
  107. "id" => $orderSN++, "name" => $moduleB["obj_name"],
  108. "icon" => $moduleB["obj_icon"], "dda" => array(),
  109. "alink" => $moduleB["obj_attach"],
  110. )
  111. );
  112. }
  113. }
  114. foreach ($forendSet["navIcon"] as &$topModule) {
  115. $orderSN = 0;
  116. foreach ($tmpModuleSet as $key => $subModule) {
  117. if ($subModule["AAA_allowed"] == true && intval($subModule["parentid"]) == $topModule["id_id"]) {
  118. array_push($topModule["dda"], array(
  119. "name" => $subModule["obj_name"], "alink" => $subModule["obj_attach"],
  120. ));
  121. array_push($forendSet["states"], array(
  122. "name" => $subModule["obj_name"], "alink" => $subModule["obj_attach"],
  123. ));
  124. }
  125. }
  126. unset($topModule["id_id"]);
  127. }
  128. return $forendSet;
  129. }
  130. //核查当前用户是否对某个模块具有权限
  131. function bizPlater_verifyPermisson($bizPlater, $objCatalog, $arrObjCodes)
  132. { // 就像外国名字一样 祖先姓-父辈姓-...-自己的姓
  133. $subSystem = intval(SUBSYS_PLAT_PCWEB);
  134. $roleList = bizPlater_getRoleSet($bizPlater);
  135. if (empty($arrObjCodes) || !is_array($arrObjCodes) || count($arrObjCodes) <= 0) {
  136. throw new GeneralException("", "授权目标对象的arrObjCodes集合不能为空!");
  137. }
  138. $allowed = false;
  139. foreach ($arrObjCodes as $objCode) {
  140. $allowed = false;
  141. foreach ($roleList as $role) {
  142. $isSysRole = (intval($role["issysrole"]) > 0); //是否系统内建角色,不可修改/删除;
  143. switch (trim($role["role_code"])) {
  144. case "SuperAdmin":
  145. return true; //一票允许 return true; 熔断直返
  146. break;
  147. default:
  148. $roleModIdSet = pdo_fetch("select bpo.id as id from base_role_permission brp
  149. inner join base_permission_object bpo on bpo.id=brp.objectid and bpo.`obj_code`=:obj_code
  150. where brp.`roleid`=:roleid and brp.`permission_run`='1';",
  151. array(":roleid" => $role["id"], ":obj_code" => trim($objCode))
  152. );
  153. if (!empty($roleModIdSet)) {
  154. $allowed = true;
  155. }
  156. break;
  157. }
  158. if ($allowed) {
  159. break;
  160. }
  161. //已获取权限,则不再遍历其他角色
  162. }
  163. //从上到下,【任一级别】模块【没有】【任何角色】权限,则中止向后遍历,直接抛出无权限 熔断退出
  164. if (empty($allowed)) {
  165. throw new GeneralException("", "此用户没有当前页面的操作权限!");
  166. }
  167. }
  168. if (empty($allowed)) {
  169. throw new GeneralException("", "此用户没有当前页面的操作权限!");
  170. }
  171. return $allowed;
  172. }
  173. /**********************验证验权角色权限相关逻辑**************************************/
  174. function bizbase_AAAEntityHandle($subSystem, $handleMode, $baseUser, $ajaxdata, $GPC)
  175. {
  176. switch ($handleMode) {
  177. case "fetchPlatUserList":
  178. $sqlTemp = "";
  179. $sqlTemp .= " select bu.id,bu.login_name,bu.mobile,br.id as roleid,br.role_name";
  180. $sqlTemp .= " from base_user bu ";
  181. $sqlTemp .= " left join base_roleuser bru on bru.userid=bu.id ";
  182. $sqlTemp .= " left join base_role br on br.id=bru.roleid ";
  183. $sqlTemp .= " where bu.`deleted`=0 and bu.subsystem=" . intval($subSystem);
  184. $backdata = pdo_fetchall($sqlTemp);
  185. return $backdata;
  186. break;
  187. case "resetPlatUserPwd":
  188. case "resetPlatUserSelfPwd":
  189. if ($handleMode == "resetPlatUserPwd") {
  190. $userid = isset($ajaxdata["userid"]) ? $ajaxdata["userid"] : $GPC["userid"];
  191. $baseUser = pdo_fetch("select * from base_user where id=" . intval($userid));
  192. if (empty($baseUser)) {
  193. throw new GeneralException("", "没有定位到此id对应的用户记录!");
  194. }
  195. } else if ($handleMode == "resetPlatUserSelfPwd") {
  196. }
  197. $newPasswd = isset($ajaxdata["newPasswd"]) ? $ajaxdata["newPasswd"] : $GPC["newPadsswd"];
  198. if (mb_strlen(trim($newPasswd)) <= 0) // && !preg_match("/^.*[a-z].*[A-Z].*\d.*$/",trim($newPasswd)))
  199. {
  200. throw new GeneralException("", "新密码长度不能为空!");
  201. }
  202. $backdata = pdo_query("update base_user set login_pwd=:login_pwd,salt=:salt where id=:id;", array(
  203. ":id" => $baseUser["id"],
  204. ":login_pwd" => bizPlater_cryptLoginPwd($newPasswd),
  205. ":salt" => random(8), //重置盐
  206. ));
  207. return $backdata;
  208. break;
  209. case "upsertPlatRoleUser":
  210. $roleId = isset($ajaxdata["roleId"]) ? $ajaxdata["roleId"] : $GPC["roleId"];
  211. $roleInfo = pdo_fetch("select * from base_role where id=" . intval($roleId));
  212. if (empty($roleInfo)) {
  213. throw new GeneralException("", "没有定位到角色记录!");
  214. }
  215. $bizData = isset($ajaxdata["bizData"]) ? $ajaxdata["bizData"] : $GPC["bizData"];
  216. if (empty($bizData)) {
  217. throw new GeneralException("", "没有传递必要的参数bizData");
  218. }
  219. $saveData["login_name"] = trim($bizData["loginName"]);
  220. if (empty($saveData["login_name"])) {
  221. throw new GeneralException("", "登录号不能为空");
  222. }
  223. if (!empty(trim($bizData["loginPwd"]))) {
  224. $saveData["login_pwd"] = bizPlater_cryptLoginPwd(trim($bizData["loginPwd"]));
  225. }
  226. $saveData["remark"] = "[" . date("Y-m-d H:i:s", time()) . "] 更新 " . trim($bizData["remark"]) . " \n";
  227. $id = $bizData["id"];
  228. if (intval($id) <= 0) {
  229. $hasUsed = pdo_fetch("select * from base_user where deleted=0 and subsystem=:subsystem and login_name=:login_name;", array(
  230. ":subsystem" => SUBSYS_PLAT_PCWEB,
  231. ":login_name" => $saveData["login_name"],
  232. ));
  233. if (!empty($hasUsed)) {
  234. throw new GeneralException("loginNameUsed", "登录号已被使用,请重新换一个吧");
  235. }
  236. $sqlParam = array();
  237. $sqlParam[":nowtime"] = time();
  238. $sqlParam[":subsystem"] = SUBSYS_PLAT_PCWEB;
  239. $sqlParam[":login_name"] = $saveData["login_name"];
  240. $sqlParam[":remark"] = $saveData["remark"];
  241. $sqlParam[":salt"] = random(8);
  242. $sqlTemp = "";
  243. $sqlTemp .= " insert into base_user set createtime=:nowtime";
  244. $sqlTemp .= " ,subsystem=:subsystem,login_name=:login_name,remark=:remark,salt=:salt ";
  245. if (!empty($saveData["login_pwd"])) {
  246. $sqlParam[":login_pwd"] = $saveData["login_pwd"];
  247. $sqlTemp .= " ,login_pwd=:login_pwd";
  248. }
  249. $sqlTemp .= " ;";
  250. $sqlTemp .= " set @handle_id=0; ";
  251. $sqlParam[":roleid"] = $roleId;
  252. $sqlTemp .= " select @handle_id:=id from base_roleuser";
  253. $sqlTemp .= " where `roleid`=:roleid and userid=LAST_INSERT_ID(); ";
  254. $sqlTemp .= " insert into base_roleuser(`roleid`, userid)";
  255. $sqlTemp .= " select :roleid, LAST_INSERT_ID() ";
  256. $sqlTemp .= " from dual where ifnull(@handle_id,0)=0 ;";
  257. $backdata = pdo_query3($sqlTemp, $sqlParam);
  258. return $backdata;
  259. } else {
  260. $userInfo = pdo_fetch("select * from base_user where id=" . intval($id));
  261. if (empty($userInfo)) {
  262. throw new GeneralException("", "没有定位到登录账号记录!");
  263. }
  264. if (intval($userInfo["subsystem"]) != SUBSYS_PLAT_PCWEB) {
  265. throw new GeneralException("", "登录账号记录不是平台账号!");
  266. }
  267. $hasUseds = pdo_fetchall("select * from base_user where deleted=0 and subsystem=:subsystem and login_name=:login_name;", array(
  268. ":subsystem" => SUBSYS_PLAT_PCWEB,
  269. ":login_name" => $saveData["login_name"],
  270. ));
  271. foreach ($hasUseds as $item) {
  272. if (intval($item["id"]) != intval($userInfo["id"])) {
  273. throw new GeneralException("loginNameUsed", "登录号已被使用,请重新换一个吧");
  274. }
  275. }
  276. $sqlParam = array();
  277. $sqlParam[":userid"] = $id;
  278. $sqlParam[":nowtime"] = time();
  279. $sqlParam[":login_name"] = $saveData["login_name"];
  280. $sqlParam[":remark"] = $saveData["remark"];
  281. $sqlTemp = "";
  282. $sqlTemp .= " update base_user set updatetime=:nowtime,login_name=:login_name,remark=concat(:remark,ifnull(remark,'')) ";
  283. if (!empty($saveData["login_pwd"])) {
  284. $sqlParam[":login_pwd"] = $saveData["login_pwd"];
  285. $sqlParam[":salt"] = random(8);
  286. $sqlTemp .= " ,login_pwd=:login_pwd,salt=:salt";
  287. }
  288. $sqlTemp .= " where id=:userid;";
  289. $sqlTemp .= " set @handle_id=0; ";
  290. $sqlParam[":roleid"] = $roleId;
  291. $sqlTemp .= " select @handle_id:=id from base_roleuser";
  292. $sqlTemp .= " where `roleid`=:roleid and userid=:userid; ";
  293. $sqlTemp .= " insert into base_roleuser(`roleid`, userid)";
  294. $sqlTemp .= " select :roleid, :userid";
  295. $sqlTemp .= " from dual where ifnull(@handle_id,0)=0 ;";
  296. $backdata = pdo_query3($sqlTemp, $sqlParam);
  297. return $backdata;
  298. }
  299. break;
  300. case "removePlatRoleUser":
  301. $userId = isset($ajaxdata["userId"]) ? $ajaxdata["userId"] : $GPC["userId"];
  302. $userInfo = pdo_fetch("select * from base_user where id=" . intval($userId));
  303. if (empty($userInfo)) {
  304. throw new GeneralException("", "没有定位到登录账号记录!");
  305. }
  306. if (intval($userInfo["subsystem"]) != SUBSYS_PLAT_PCWEB) {
  307. throw new GeneralException("", "登录账号记录不是平台账号!");
  308. }
  309. if (intval($userInfo["deleted"]) != 0) {
  310. throw new GeneralException("", "登录账号记录已被删除!");
  311. }
  312. $reason = isset($ajaxdata["reason"]) ? $ajaxdata["reason"] : $GPC["reason"];
  313. $sqlParam = array();
  314. $sqlParam[":userid"] = $userId;
  315. $sqlParam[":nowtime"] = time();
  316. $sqlParam[":remark"] = "[" . date("Y-m-d H:i:s", time()) . "] 删除 $reason \n";
  317. $sqlTemp = "";
  318. $sqlTemp .= " update base_user set updatetime=:nowtime";
  319. $sqlTemp .= " ,deleted=1,remark=concat(:remark,ifnull(remark,'')) ";
  320. $sqlTemp .= " where id=:userid;";
  321. $sqlTemp .= " delete from base_roleuser where userid=:userid; ";
  322. $backdata = pdo_query3($sqlTemp, $sqlParam);
  323. return $backdata;
  324. break;
  325. default:
  326. throw new GeneralException("", "不支持的handleMode!");
  327. }
  328. }
  329. function bizPlater_undoList()
  330. {
  331. $backdata = array();
  332. $backdata["recruit_waitaudit"] = pdo_fetchcolumn("select count(*) from biz_trader_recruit where deleted=0 and `status`=1");
  333. $backdata["recruit_waitaudit"] = intval($backdata["recruit_waitaudit"]) <= 0 ? null : intval($backdata["recruit_waitaudit"]);
  334. $backdata["suggestion_unsettled"] = pdo_fetchcolumn("select count(*) from biz_interaction where deleted=0 and biz_catalog<=1 and `status`<3 ");
  335. $backdata["suggestion_unsettled"] = intval($backdata["suggestion_unsettled"]) <= 0 ? null : intval($backdata["suggestion_unsettled"]);
  336. $backdata["complaint_unsettled"] = pdo_fetchcolumn("select count(*) from biz_interaction where deleted=0 and biz_catalog>=2 and `status`<3 ");
  337. $backdata["complaint_unsettled"] = intval($backdata["complaint_unsettled"]) <= 0 ? null : intval($backdata["complaint_unsettled"]);
  338. $backdata["tdwk_overtimepay"] = intval(pdo_fetchcolumn("select count(*) from biz_todowork tdwk where tdwk.deleted=0 and (tdwk.`status`=4 and " . time() . "-ifnull(tdwk.worked_finishtime,0)>24*3600)"));
  339. //$backdata["tdwk_denypay"] = intval(pdo_fetchcolumn("select count(*) from biz_todowork tdwk where tdwk.deleted=0 and (tdwk.`status`=-5)"));
  340. //$backdata["tdwk_waitpay"] = $backdata["tdwk_overtimepay"] + $backdata["tdwk_denypay"];
  341. $backdata["tdwk_denypay"] = intval(pdo_fetchcolumn("select count(*) from biz_todowork tdwk where tdwk.deleted=0 and (tdwk.`status`<0)"));
  342. $backdata["tdwk_waitpay"] = $backdata["tdwk_overtimepay"] + $backdata["tdwk_denypay"];
  343. if ($backdata["tdwk_waitpay"] <= 0) {
  344. $backdata["tdwk_waitpay"] = null;
  345. }
  346. if ($backdata["tdwk_overtimepay"] <= 0) {
  347. $backdata["tdwk_overtimepay"] = null;
  348. }
  349. if ($backdata["tdwk_denypay"] <= 0) {
  350. $backdata["tdwk_denypay"] = null;
  351. }
  352. $backdata["activityorder_unreaded"] = intval(pdo_fetchcolumn("select count(*) from biz_market_activity_order where deleted=0 and plater_readed=0;"));
  353. if ($backdata["activityorder_unreaded"] <= 0) {
  354. $backdata["activityorder_unreaded"] = null;
  355. }
  356. $backdata["tdupgrade_unaudit"] = intval(pdo_fetchcolumn("select count(*) from biz_trader where deleted=0 and catalog=0 and certif_confirmed=1 and bizlicense_pic<>'';"));
  357. if ($backdata["tdupgrade_unaudit"] <= 0) {
  358. $backdata["tdupgrade_unaudit"] = null;
  359. }
  360. $backdata["tdupgrade_unaudit_gesture"] = intval(pdo_fetchcolumn("select count(*) from biz_trader where deleted=0 and (lawer_idcard != '' and ((catalog = '0' and (certif_confirmed = '0' or (certif_confirmed = '1' && company_idcard !=''))) or (catalog = '1' and certif_confirmed = '0')));"));
  361. if ($backdata["tdupgrade_unaudit_gesture"] <= 0) {
  362. $backdata["tdupgrade_unaudit_gesture"] = null;
  363. }
  364. $backdata["tdwk_refuseypay"] = intval(pdo_fetchcolumn("select count(*) from biz_todowork tdwk where tdwk.deleted=0 and (tdwk.`status`=90)"));
  365. if ($backdata["tdwk_refuseypay"] <= 0) {
  366. $backdata["tdwk_refuseypay"] = null;
  367. }
  368. return $backdata;
  369. }