RegisterfieldController.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <?php
  2. namespace app\index\controller;
  3. use think\exception\ValidateException;
  4. use think\facade\Validate;
  5. use app\model\RegisterField;
  6. use app\model\Member;
  7. use app\model\Technical;
  8. use app\model\Tuanzhang;
  9. use app\model\Agent;
  10. use app\model\Partner;
  11. use app\model\Category;
  12. use app\model\Config;
  13. use app\model\Users;
  14. use app\model\Store;
  15. use app\model\Operatingcity;
  16. use app\model\AgentCode;
  17. use app\model\Order;
  18. use app\model\UuidRelation;
  19. class RegisterfieldController extends Base
  20. {
  21. public function list()
  22. {
  23. $ptype = input('get.ptype', '', 'serach_in');
  24. $update = input('get.update', '', 'serach_in');
  25. $orderid = input('get.orderid', '', 'serach_in');
  26. $technicalid = input('get.technicalid', '', 'serach_in');
  27. if (empty($ptype)) {
  28. $ptype = 'users';
  29. }
  30. $uid = UID();
  31. if ($ptype == 'agent') {
  32. $agent = Agent::where('uid', $uid)->find();
  33. if (!empty($agent)) {
  34. if (empty($update)) {
  35. return $this->json(['is_submit' => 1]);
  36. }
  37. $infodata = $agent->toArray();
  38. }
  39. }
  40. if ($ptype == 'partner') {
  41. $partner = Partner::where('uid', $uid)->find();
  42. if (!empty($partner)) {
  43. if (empty($update)) {
  44. return $this->json(['is_submit' => 1]);
  45. }
  46. $infodata = $partner->toArray();
  47. }
  48. }
  49. if ($ptype == 'technical') {
  50. $uuid = UuidRelation::getuuid(UID(), 'technical');
  51. if (!empty($technicalid)) {
  52. $technical = Technical::find($technicalid);
  53. } else if (!empty($uuid)) {
  54. $technical = Technical::where('uuid', $uuid)->find();
  55. }
  56. if (!empty($technical)) {
  57. if (empty($update)) {
  58. return $this->json(['is_submit' => 1]);
  59. }
  60. $infodata = $technical->toArray();
  61. }
  62. }
  63. if ($ptype == 'tuanzhang') {
  64. $uuid = UuidRelation::getuuid(UID(), 'tuanzhang');
  65. if (!empty($uuid)) {
  66. $tuanzhang = Tuanzhang::where('uuid', $uuid)->find();
  67. if (!empty($tuanzhang)) {
  68. if (empty($update)) {
  69. return $this->json(['is_submit' => 1]);
  70. }
  71. $infodata = $tuanzhang->toArray();
  72. }
  73. }
  74. }
  75. if ($ptype == 'store') {
  76. $store = Store::getInfobyuid(UID());
  77. if (!empty($store)) {
  78. if (empty($update)) {
  79. return $this->json(['is_submit' => 1]);
  80. }
  81. $infodata = $store;
  82. }
  83. }
  84. if ($ptype == 'operatingcity') {
  85. $uuid = UuidRelation::getuuid(UID(), 'operatingcity');
  86. if (!empty($uuid)) {
  87. $Operatingcity = Operatingcity::where('uuid', $uuid)->find();
  88. if (!empty($Operatingcity)) {
  89. if (empty($update)) {
  90. return $this->json(['is_submit' => 1]);
  91. }
  92. $infodata = $Operatingcity->toArray();
  93. }
  94. }
  95. }
  96. if ($ptype == 'complete') {
  97. $order = Order::where('id', $orderid)->find();
  98. if (!empty($order)) {
  99. $infodata['customtext'] = $order->customtext;
  100. }
  101. }
  102. $customtext = iunserializer($infodata['customtext']);
  103. $nousername = $update;
  104. $data = RegisterField::getfrontinputField($ptype, $nousername);
  105. foreach ($data as &$vo) {
  106. if ($vo['is_sys'] == 1) {
  107. $vo['fieldsvalue'] = $infodata[$vo['fieldsmingcheng']];
  108. if ($vo['inputtype'] == 'lbs') {
  109. if (empty($vo['fieldsvalue'])) {
  110. $vo['fieldsvalue'] = [];
  111. $vo['fieldsvalue']['region_name'] = $infodata['province_name'] . $infodata['city_name'] . $infodata['district_name'];
  112. } else {
  113. if ($vo['is_sys'] == 1) {
  114. $vo['fieldsvalue'] = [];
  115. $vo['fieldsvalue']['province_name'] = $infodata['province_name'];
  116. $vo['fieldsvalue']['city_name'] = $infodata['city_name'];
  117. $vo['fieldsvalue']['district_name'] = $infodata['district_name'];
  118. $vo['fieldsvalue']['address'] = $infodata['dizhi'];
  119. $vo['fieldsvalue']['latitude'] = $infodata['latitude'];
  120. $vo['fieldsvalue']['longitude'] = $infodata['longitude'];
  121. $vo['fieldsvalue']['region_name'] = $infodata['region_name'];
  122. } else {
  123. $vo['fieldsvalue'] = iunserializer($vo['fieldsvalue']);
  124. }
  125. }
  126. }
  127. if ($vo['inputtype'] == 'checkbox' && $vo['fieldsmingcheng'] == 'cate_ids') {
  128. if (empty($vo['fieldsvalue'])) {
  129. $vo['fieldsvalue'] = [];
  130. } else {
  131. $vo['fieldsvalue'] = explode(',', $vo['fieldsvalue']);
  132. }
  133. if ($vo['ptype'] == 'technical') {
  134. $ctopptype = 2;
  135. } else {
  136. $ctopptype = '';
  137. }
  138. $vo['selectvaluearray'] = Category::gettoparray($ctopptype);
  139. } elseif ($vo['fieldsmingcheng'] == 'sid') {
  140. if (empty($vo['fieldsvalue'])) {
  141. $vo['fieldsvalue'] = [];
  142. }
  143. $vo['selectvaluearray'] = Store::getpcarray();
  144. } else {
  145. if (!empty($vo['selectvalue'])) {
  146. $vo['fieldsvalue'] = [];
  147. $selectvaluearray = explode(',', $vo['selectvalue']);
  148. if (is_array($selectvaluearray)) {
  149. foreach ($selectvaluearray as $key => $svo) {
  150. $vo['selectvaluearray'][$key]['title'] = $svo;
  151. }
  152. }
  153. }
  154. }
  155. } else {
  156. $vo['fieldsvalue'] = $customtext[$vo['inputtype']][$vo['id']];
  157. }
  158. if ($vo['inputtype'] == 'pics') {
  159. $vo['fieldsvalue1'] = $vo['fieldsvalue'];
  160. if (empty($vo['fieldsvalue'])) {
  161. $vo['fieldsvalue'] = [];
  162. } else {
  163. $vo['fieldsvalue'] = explode(',', $vo['fieldsvalue']);
  164. }
  165. }
  166. }
  167. return $this->json(['data' => $data]);
  168. }
  169. public function view()
  170. {
  171. $ptype = input('get.ptype', '', 'serach_in');
  172. $orderid = input('get.orderid', '', 'serach_in');
  173. $technicalid = input('get.technicalid', '', 'serach_in');
  174. if (empty($ptype)) {
  175. $ptype = 'users';
  176. }
  177. $uid = UID();
  178. if ($ptype == 'agent') {
  179. $agent = Agent::where('uid', $uid)->find();
  180. if (!empty($agent)) {
  181. $infodata = $agent->toArray();
  182. }
  183. }
  184. if ($ptype == 'partner') {
  185. $partner = Partner::where('uid', $uid)->find();
  186. if (!empty($partner)) {
  187. $infodata = $partner->toArray();
  188. }
  189. }
  190. if ($ptype == 'technical') {
  191. $uuid = UuidRelation::getuuid(UID(), 'technical');
  192. if (!empty($technicalid)) {
  193. $technical = Technical::find($technicalid);
  194. } else if (!empty($uuid)) {
  195. $technical = Technical::where('uuid', $uuid)->find();
  196. }
  197. if (!empty($technical)) {
  198. $infodata = $technical->toArray();
  199. }
  200. }
  201. if ($ptype == 'tuanzhang') {
  202. $uuid = UuidRelation::getuuid(UID(), 'tuanzhang');
  203. if (!empty($uuid)) {
  204. $tuanzhang = Tuanzhang::where('uuid', $uuid)->find();
  205. if (!empty($tuanzhang)) {
  206. $infodata = $tuanzhang->toArray();
  207. }
  208. }
  209. }
  210. if ($ptype == 'store') {
  211. $uuid = UuidRelation::getuuid(UID(), 'store');
  212. if (!empty($uuid)) {
  213. $store = Store::where('uuid', $uuid)->find();
  214. if (!empty($store)) {
  215. $infodata = $store->toArray();
  216. }
  217. }
  218. }
  219. if ($ptype == 'operatingcity') {
  220. $uuid = UuidRelation::getuuid(UID(), 'operatingcity');
  221. if (!empty($uuid)) {
  222. $Operatingcity = Operatingcity::where('uuid', $uuid)->find();
  223. if (!empty($Operatingcity)) {
  224. $infodata = $Operatingcity->toArray();
  225. }
  226. }
  227. }
  228. if ($ptype == 'complete') {
  229. $order = Order::where('id', $orderid)->find();
  230. if (!empty($order)) {
  231. $infodata['customtext'] = $order->customtext;
  232. }
  233. }
  234. $customtext = iunserializer($infodata['customtext']);
  235. $data = RegisterField::getfrontField($ptype);
  236. foreach ($data as &$vo) {
  237. if ($vo['is_sys'] == 1) {
  238. $vo['fieldsvalue'] = $infodata[$vo['fieldsmingcheng']];
  239. if ($vo['inputtype'] == 'lbs') {
  240. if (empty($vo['fieldsvalue'])) {
  241. $vo['fieldsvalue'] = [];
  242. $vo['fieldsvalue']['region_name'] = $infodata['province_name'] . $infodata['city_name'] . $infodata['district_name'];
  243. } else {
  244. if ($vo['is_sys'] == 1) {
  245. $vo['fieldsvalue'] = [];
  246. $vo['fieldsvalue']['province_name'] = $infodata['province_name'];
  247. $vo['fieldsvalue']['city_name'] = $infodata['city_name'];
  248. $vo['fieldsvalue']['district_name'] = $infodata['district_name'];
  249. $vo['fieldsvalue']['address'] = $infodata['dizhi'];
  250. $vo['fieldsvalue']['latitude'] = $infodata['latitude'];
  251. $vo['fieldsvalue']['longitude'] = $infodata['longitude'];
  252. $vo['fieldsvalue']['region_name'] = $infodata['region_name'];
  253. } else {
  254. $vo['fieldsvalue'] = iunserializer($vo['fieldsvalue']);
  255. }
  256. }
  257. }
  258. if ($vo['inputtype'] == 'checkbox' && $vo['fieldsmingcheng'] == 'cate_ids') {
  259. if (empty($vo['fieldsvalue'])) {
  260. $vo['fieldsvalue'] = [];
  261. } else {
  262. $vo['fieldsvalue'] = explode(',', $vo['fieldsvalue']);
  263. }
  264. if ($vo['ptype'] == 'technical') {
  265. $ctopptype = 2;
  266. } else {
  267. $ctopptype = '';
  268. }
  269. $vo['selectvaluearray'] = Category::gettoparray($ctopptype);
  270. } elseif ($vo['fieldsmingcheng'] == 'sid') {
  271. if (empty($vo['fieldsvalue'])) {
  272. $vo['fieldsvalue'] = [];
  273. }
  274. $vo['selectvaluearray'] = Store::getpcarray();
  275. } else {
  276. if (!empty($vo['selectvalue'])) {
  277. $vo['fieldsvalue'] = [];
  278. $selectvaluearray = explode(',', $vo['selectvalue']);
  279. if (is_array($selectvaluearray)) {
  280. foreach ($selectvaluearray as $key => $svo) {
  281. $vo['selectvaluearray'][$key]['title'] = $svo;
  282. }
  283. }
  284. }
  285. }
  286. } else {
  287. $vo['fieldsvalue'] = $customtext[$vo['inputtype']][$vo['id']];
  288. }
  289. if ($vo['inputtype'] == 'pics') {
  290. $vo['fieldsvalue1'] = $vo['fieldsvalue'];
  291. if (empty($vo['fieldsvalue'])) {
  292. $vo['fieldsvalue'] = [];
  293. } else {
  294. $vo['fieldsvalue'] = explode(',', $vo['fieldsvalue']);
  295. }
  296. }
  297. }
  298. return $this->json(['data' => $data]);
  299. }
  300. public function update()
  301. {
  302. $uuid = uniqid(rand(1, 10000));
  303. $update = input('post.update', '', 'serach_in');
  304. $postdata['fields'] = json_decode(input('post.registerfield'), true);
  305. $registerfield = $postdata['fields'];
  306. $regdata = RegisterField::fieldToData($postdata);
  307. $data = $regdata['data'];
  308. $validate = Validate::rule($regdata['rule']);
  309. if (!$validate->check($data)) {
  310. return $this->json(['errno' => 1, 'msg' => $validate->getError()]);
  311. }
  312. if ($data['username']) {
  313. $data['uuid'] = $uuid;
  314. }
  315. $usersdata['password'] = $data['password'];
  316. unset($data['password']);
  317. if (empty($id)) {
  318. $usersdata['username'] = trim($data['username']);
  319. }
  320. unset($data['username']);
  321. if ($usersdata['username']) {
  322. if (Users::where('username', $usersdata['username'])->find()) {
  323. throw new ValidateException('用户名已被占用');
  324. }
  325. }
  326. $data['weid'] = weid();
  327. unset($data['create_time']);
  328. try {
  329. if ($registerfield[0]['ptype'] == 'member') {
  330. $Configdata = Config::getconfig('member');
  331. if ($Configdata['reg_check'] == 1) {
  332. $data['status'] = 0;
  333. } else {
  334. $data['status'] = 1;
  335. }
  336. $data['id'] = UID();
  337. Member::update($data);
  338. }
  339. if ($registerfield[0]['ptype'] == 'technical') {
  340. if ($data['photoalbum']) {
  341. $data['touxiang'] = explode(',', $data['photoalbum'])[0];
  342. }
  343. if (empty($update)) {
  344. $data['status'] = 0;
  345. $data['sort'] = 100;
  346. $data['uid'] = UID();
  347. $res = Technical::create($data);
  348. } else {
  349. $uuid = UuidRelation::getuuid(UID(), 'technical');
  350. Technical::where('uuid', $uuid)->update($data);
  351. }
  352. }
  353. if ($registerfield[0]['ptype'] == 'tuanzhang') {
  354. if (empty($update)) {
  355. $data['status'] = 0;
  356. $data['sort'] = 100;
  357. $data['uid'] = UID();
  358. $res = Tuanzhang::create($data);
  359. } else {
  360. $uuid = UuidRelation::getuuid(UID(), 'tuanzhang');
  361. Tuanzhang::where('uuid', $uuid)->update($data);
  362. }
  363. }
  364. if ($registerfield[0]['ptype'] == 'agent') {
  365. unset($data['uuid']);
  366. $Configdata = Config::getconfig('agent');
  367. if ($Configdata['share_condition'] == 2) {
  368. $data['status'] = 0;
  369. } else if ($Configdata['share_condition'] == 3) {
  370. $data['status'] = 1;
  371. }
  372. if (!empty($data['pid_code'])) {
  373. $puid = AgentCode::getuid($data['pid_code']);
  374. if (!empty($puid)) {
  375. Member::where('id', UID())->update(['pid' => $puid]);
  376. }
  377. }
  378. $data['uid'] = UID();
  379. Agent::create($data);
  380. }
  381. if ($registerfield[0]['ptype'] == 'partner') {
  382. unset($data['uuid']);
  383. $Configdata = Config::getconfig('partner');
  384. $data['uid'] = UID();
  385. Partner::create($data);
  386. }
  387. if ($registerfield[0]['ptype'] == 'store') {
  388. if (empty($update)) {
  389. $data['status'] = 0;
  390. $data['sort'] = 100;
  391. $data['uid'] = UID();
  392. $res = Store::create($data);
  393. } else {
  394. $uuid = UuidRelation::getuuid(UID(), 'store');
  395. Store::where('uuid', $uuid)->update($data);
  396. }
  397. }
  398. if ($registerfield[0]['ptype'] == 'operatingcity') {
  399. if (empty($update)) {
  400. $data['status'] = 0;
  401. $data['sort'] = 100;
  402. $res = Operatingcity::create($data);
  403. } else {
  404. $uuid = UuidRelation::getuuid(UID(), 'operatingcity');
  405. Operatingcity::where('uuid', $uuid)->update($data);
  406. }
  407. }
  408. if ($registerfield[0]['ptype'] == 'store' || $registerfield[0]['ptype'] == 'tuanzhang' || $registerfield[0]['ptype'] == 'technical' || $registerfield[0]['ptype'] == 'operatingcity') {
  409. if ($res->id && !empty($usersdata['username'])) {
  410. if (!empty($usersdata['password'])) {
  411. $usersdata["salt"] = substr(md5(uniqid()), 8, 8);
  412. $usersdata['password'] = pass_hash($usersdata['password'], $usersdata["salt"]);
  413. } else {
  414. unset($usersdata['password']);
  415. }
  416. if ($registerfield[0]['ptype'] == 'store') {
  417. $usersdata['sid'] = $res->id;
  418. }
  419. if ($registerfield[0]['ptype'] == 'operatingcity') {
  420. $usersdata['ocid'] = $res->id;
  421. }
  422. if ($registerfield[0]['ptype'] == 'tuanzhang') {
  423. $usersdata['tzid'] = $res->id;
  424. }
  425. $usersdata['weid'] = weid();
  426. $usersdata['uuid'] = $data['uuid'];
  427. $usersdata['w7uid'] = 0;
  428. Users::create($usersdata);
  429. UuidRelation::create(['weid' => weid(), 'ptype' => $registerfield[0]['ptype'], 'uuid' => $res['uuid'], 'uid' => UID()]);
  430. }
  431. }
  432. } catch (\Exception $e) {
  433. throw new ValidateException($e->getMessage());
  434. }
  435. $msg = '提交成功';
  436. return $this->json(['msg' => $msg, 'data' => $data]);
  437. }
  438. }