RegisterfieldController.php 19 KB

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