123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- <?php
- namespace app\index\controller;
- use think\exception\ValidateException;
- use think\facade\Validate;
- use app\model\RegisterField;
- use app\model\Member;
- use app\model\Technical;
- use app\model\Tuanzhang;
- use app\model\Agent;
- use app\model\Partner;
- use app\model\Category;
- use app\model\Config;
- use app\model\Users;
- use app\model\Store;
- use app\model\Operatingcity;
- use app\model\AgentCode;
- use app\model\Order;
- use app\model\UuidRelation;
- class RegisterfieldController extends Base
- {
- public function list()
- {
- $ptype = input('get.ptype', '', 'serach_in');
- $update = input('get.update', '', 'serach_in');
- $orderid = input('get.orderid', '', 'serach_in');
- $technicalid = input('get.technicalid', '', 'serach_in');
- if (empty($ptype)) {
- $ptype = 'users';
- }
- $uid = UID();
- if ($ptype == 'agent') {
- $agent = Agent::where('uid', $uid)->find();
- if (!empty($agent)) {
- if (empty($update)) {
- return $this->json(['is_submit' => 1]);
- }
- $infodata = $agent->toArray();
- }
- }
- if ($ptype == 'partner') {
- $partner = Partner::where('uid', $uid)->find();
- if (!empty($partner)) {
- if (empty($update)) {
- return $this->json(['is_submit' => 1]);
- }
- $infodata = $partner->toArray();
- }
- }
- if ($ptype == 'technical') {
- $uuid = UuidRelation::getuuid(UID(), 'technical');
- if (!empty($technicalid)) {
- $technical = Technical::find($technicalid);
- } else if (!empty($uuid)) {
- $technical = Technical::where('uuid', $uuid)->find();
- }
- if (!empty($technical)) {
- if (empty($update)) {
- return $this->json(['is_submit' => 1]);
- }
- $infodata = $technical->toArray();
- }
- }
- if ($ptype == 'tuanzhang') {
- $uuid = UuidRelation::getuuid(UID(), 'tuanzhang');
- if (!empty($uuid)) {
- $tuanzhang = Tuanzhang::where('uuid', $uuid)->find();
- if (!empty($tuanzhang)) {
- if (empty($update)) {
- return $this->json(['is_submit' => 1]);
- }
- $infodata = $tuanzhang->toArray();
- }
- }
- }
- if ($ptype == 'store') {
- $store = Store::getInfobyuid(UID());
- if (!empty($store)) {
- if (empty($update)) {
- return $this->json(['is_submit' => 1]);
- }
- $infodata = $store;
- }
- }
- if ($ptype == 'operatingcity') {
- $uuid = UuidRelation::getuuid(UID(), 'operatingcity');
- if (!empty($uuid)) {
- $Operatingcity = Operatingcity::where('uuid', $uuid)->find();
- if (!empty($Operatingcity)) {
- if (empty($update)) {
- return $this->json(['is_submit' => 1]);
- }
- $infodata = $Operatingcity->toArray();
- }
- }
- }
- if ($ptype == 'complete') {
- $order = Order::where('id', $orderid)->find();
- if (!empty($order)) {
- $infodata['customtext'] = $order->customtext;
- }
- }
- $customtext = iunserializer($infodata['customtext']);
- $nousername = $update;
- $data = RegisterField::getfrontinputField($ptype, $nousername);
- foreach ($data as &$vo) {
- if ($vo['is_sys'] == 1) {
- $vo['fieldsvalue'] = $infodata[$vo['fieldsmingcheng']];
- if ($vo['inputtype'] == 'lbs') {
- if (empty($vo['fieldsvalue'])) {
- $vo['fieldsvalue'] = [];
- $vo['fieldsvalue']['region_name'] = $infodata['province_name'] . $infodata['city_name'] . $infodata['district_name'];
- } else {
- if ($vo['is_sys'] == 1) {
- $vo['fieldsvalue'] = [];
- $vo['fieldsvalue']['province_name'] = $infodata['province_name'];
- $vo['fieldsvalue']['city_name'] = $infodata['city_name'];
- $vo['fieldsvalue']['district_name'] = $infodata['district_name'];
- $vo['fieldsvalue']['address'] = $infodata['dizhi'];
- $vo['fieldsvalue']['latitude'] = $infodata['latitude'];
- $vo['fieldsvalue']['longitude'] = $infodata['longitude'];
- $vo['fieldsvalue']['region_name'] = $infodata['region_name'];
- } else {
- $vo['fieldsvalue'] = iunserializer($vo['fieldsvalue']);
- }
- }
- }
- if ($vo['inputtype'] == 'checkbox' && $vo['fieldsmingcheng'] == 'cate_ids') {
- if (empty($vo['fieldsvalue'])) {
- $vo['fieldsvalue'] = [];
- } else {
- $vo['fieldsvalue'] = explode(',', $vo['fieldsvalue']);
- }
- if ($vo['ptype'] == 'technical') {
- $ctopptype = 2;
- } else {
- $ctopptype = '';
- }
- $vo['selectvaluearray'] = Category::gettoparray($ctopptype);
- } elseif ($vo['fieldsmingcheng'] == 'sid') {
- if (empty($vo['fieldsvalue'])) {
- $vo['fieldsvalue'] = [];
- }
- $vo['selectvaluearray'] = Store::getpcarray();
- } else {
- if (!empty($vo['selectvalue'])) {
- $vo['fieldsvalue'] = [];
- $selectvaluearray = explode(',', $vo['selectvalue']);
- if (is_array($selectvaluearray)) {
- foreach ($selectvaluearray as $key => $svo) {
- $vo['selectvaluearray'][$key]['title'] = $svo;
- }
- }
- }
- }
- } else {
- $vo['fieldsvalue'] = $customtext[$vo['inputtype']][$vo['id']];
- }
- if ($vo['inputtype'] == 'pics') {
- $vo['fieldsvalue1'] = $vo['fieldsvalue'];
- if (empty($vo['fieldsvalue'])) {
- $vo['fieldsvalue'] = [];
- } else {
- $vo['fieldsvalue'] = explode(',', $vo['fieldsvalue']);
- }
- }
- }
- return $this->json(['data' => $data]);
- }
- public function view()
- {
- $ptype = input('get.ptype', '', 'serach_in');
- $orderid = input('get.orderid', '', 'serach_in');
- $technicalid = input('get.technicalid', '', 'serach_in');
- if (empty($ptype)) {
- $ptype = 'users';
- }
- $uid = UID();
- if ($ptype == 'agent') {
- $agent = Agent::where('uid', $uid)->find();
- if (!empty($agent)) {
- $infodata = $agent->toArray();
- }
- }
- if ($ptype == 'partner') {
- $partner = Partner::where('uid', $uid)->find();
- if (!empty($partner)) {
- $infodata = $partner->toArray();
- }
- }
- if ($ptype == 'technical') {
- $uuid = UuidRelation::getuuid(UID(), 'technical');
- if (!empty($technicalid)) {
- $technical = Technical::find($technicalid);
- } else if (!empty($uuid)) {
- $technical = Technical::where('uuid', $uuid)->find();
- }
- if (!empty($technical)) {
- $infodata = $technical->toArray();
- }
- }
- if ($ptype == 'tuanzhang') {
- $uuid = UuidRelation::getuuid(UID(), 'tuanzhang');
- if (!empty($uuid)) {
- $tuanzhang = Tuanzhang::where('uuid', $uuid)->find();
- if (!empty($tuanzhang)) {
- $infodata = $tuanzhang->toArray();
- }
- }
- }
- if ($ptype == 'store') {
- $uuid = UuidRelation::getuuid(UID(), 'store');
- if (!empty($uuid)) {
- $store = Store::where('uuid', $uuid)->find();
- if (!empty($store)) {
- $infodata = $store->toArray();
- }
- }
- }
- if ($ptype == 'operatingcity') {
- $uuid = UuidRelation::getuuid(UID(), 'operatingcity');
- if (!empty($uuid)) {
- $Operatingcity = Operatingcity::where('uuid', $uuid)->find();
- if (!empty($Operatingcity)) {
- $infodata = $Operatingcity->toArray();
- }
- }
- }
- if ($ptype == 'complete') {
- $order = Order::where('id', $orderid)->find();
- if (!empty($order)) {
- $infodata['customtext'] = $order->customtext;
- }
- }
- $customtext = iunserializer($infodata['customtext']);
- $data = RegisterField::getfrontField($ptype);
- foreach ($data as &$vo) {
- if ($vo['is_sys'] == 1) {
- $vo['fieldsvalue'] = $infodata[$vo['fieldsmingcheng']];
- if ($vo['inputtype'] == 'lbs') {
- if (empty($vo['fieldsvalue'])) {
- $vo['fieldsvalue'] = [];
- $vo['fieldsvalue']['region_name'] = $infodata['province_name'] . $infodata['city_name'] . $infodata['district_name'];
- } else {
- if ($vo['is_sys'] == 1) {
- $vo['fieldsvalue'] = [];
- $vo['fieldsvalue']['province_name'] = $infodata['province_name'];
- $vo['fieldsvalue']['city_name'] = $infodata['city_name'];
- $vo['fieldsvalue']['district_name'] = $infodata['district_name'];
- $vo['fieldsvalue']['address'] = $infodata['dizhi'];
- $vo['fieldsvalue']['latitude'] = $infodata['latitude'];
- $vo['fieldsvalue']['longitude'] = $infodata['longitude'];
- $vo['fieldsvalue']['region_name'] = $infodata['region_name'];
- } else {
- $vo['fieldsvalue'] = iunserializer($vo['fieldsvalue']);
- }
- }
- }
- if ($vo['inputtype'] == 'checkbox' && $vo['fieldsmingcheng'] == 'cate_ids') {
- if (empty($vo['fieldsvalue'])) {
- $vo['fieldsvalue'] = [];
- } else {
- $vo['fieldsvalue'] = explode(',', $vo['fieldsvalue']);
- }
- if ($vo['ptype'] == 'technical') {
- $ctopptype = 2;
- } else {
- $ctopptype = '';
- }
- $vo['selectvaluearray'] = Category::gettoparray($ctopptype);
- } elseif ($vo['fieldsmingcheng'] == 'sid') {
- if (empty($vo['fieldsvalue'])) {
- $vo['fieldsvalue'] = [];
- }
- $vo['selectvaluearray'] = Store::getpcarray();
- } else {
- if (!empty($vo['selectvalue'])) {
- $vo['fieldsvalue'] = [];
- $selectvaluearray = explode(',', $vo['selectvalue']);
- if (is_array($selectvaluearray)) {
- foreach ($selectvaluearray as $key => $svo) {
- $vo['selectvaluearray'][$key]['title'] = $svo;
- }
- }
- }
- }
- } else {
- $vo['fieldsvalue'] = $customtext[$vo['inputtype']][$vo['id']];
- }
- if ($vo['inputtype'] == 'pics') {
- $vo['fieldsvalue1'] = $vo['fieldsvalue'];
- if (empty($vo['fieldsvalue'])) {
- $vo['fieldsvalue'] = [];
- } else {
- $vo['fieldsvalue'] = explode(',', $vo['fieldsvalue']);
- }
- }
- }
- return $this->json(['data' => $data]);
- }
-
- public function update()
- {
- $uuid = uniqid(rand(1, 10000));
- $update = input('post.update', '', 'serach_in');
- $postdata['fields'] = json_decode(input('post.registerfield'), true);
- $registerfield = $postdata['fields'];
- $regdata = RegisterField::fieldToData($postdata);
- $data = $regdata['data'];
- $validate = Validate::rule($regdata['rule']);
- if (!$validate->check($data)) {
- return $this->json(['errno' => 1, 'msg' => $validate->getError()]);
- }
- if ($data['username']) {
- $data['uuid'] = $uuid;
- }
- $usersdata['password'] = $data['password'];
- unset($data['password']);
- if (empty($id)) {
- $usersdata['username'] = trim($data['username']);
- }
- unset($data['username']);
- if ($usersdata['username']) {
- if (Users::where('username', $usersdata['username'])->find()) {
- throw new ValidateException('用户名已被占用');
- }
- }
- $data['weid'] = weid();
- unset($data['create_time']);
- try {
- if ($registerfield[0]['ptype'] == 'member') {
- $Configdata = Config::getconfig('member');
- if ($Configdata['reg_check'] == 1) {
- $data['status'] = 0;
- } else {
- $data['status'] = 1;
- }
- $data['id'] = UID();
- Member::update($data);
- }
- if ($registerfield[0]['ptype'] == 'technical') {
- if ($data['photoalbum']) {
- $data['touxiang'] = explode(',', $data['photoalbum'])[0];
- }
- if (empty($update)) {
- $data['status'] = 0;
- $data['sort'] = 100;
- $data['uid'] = UID();
- $res = Technical::create($data);
- } else {
- $uuid = UuidRelation::getuuid(UID(), 'technical');
- Technical::where('uuid', $uuid)->update($data);
- }
- }
- if ($registerfield[0]['ptype'] == 'tuanzhang') {
- if (empty($update)) {
- $data['status'] = 0;
- $data['sort'] = 100;
- $data['uid'] = UID();
- $res = Tuanzhang::create($data);
- } else {
- $uuid = UuidRelation::getuuid(UID(), 'tuanzhang');
- Tuanzhang::where('uuid', $uuid)->update($data);
- }
- }
- if ($registerfield[0]['ptype'] == 'agent') {
- unset($data['uuid']);
- $Configdata = Config::getconfig('agent');
- if ($Configdata['share_condition'] == 2) {
- $data['status'] = 0;
- } else if ($Configdata['share_condition'] == 3) {
- $data['status'] = 1;
- }
- if (!empty($data['pid_code'])) {
- $puid = AgentCode::getuid($data['pid_code']);
- if (!empty($puid)) {
- Member::where('id', UID())->update(['pid' => $puid]);
- }
- }
- $data['uid'] = UID();
- Agent::create($data);
- }
- if ($registerfield[0]['ptype'] == 'partner') {
- unset($data['uuid']);
- $Configdata = Config::getconfig('partner');
- $data['uid'] = UID();
- Partner::create($data);
- }
- if ($registerfield[0]['ptype'] == 'store') {
- if (empty($update)) {
- $data['status'] = 0;
- $data['sort'] = 100;
- $data['uid'] = UID();
- $res = Store::create($data);
- } else {
- $uuid = UuidRelation::getuuid(UID(), 'store');
- Store::where('uuid', $uuid)->update($data);
- }
- }
- if ($registerfield[0]['ptype'] == 'operatingcity') {
- if (empty($update)) {
- $data['status'] = 0;
- $data['sort'] = 100;
- $res = Operatingcity::create($data);
- } else {
- $uuid = UuidRelation::getuuid(UID(), 'operatingcity');
- Operatingcity::where('uuid', $uuid)->update($data);
- }
- }
- if ($registerfield[0]['ptype'] == 'store' || $registerfield[0]['ptype'] == 'tuanzhang' || $registerfield[0]['ptype'] == 'technical' || $registerfield[0]['ptype'] == 'operatingcity') {
- if ($res->id && !empty($usersdata['username'])) {
- if (!empty($usersdata['password'])) {
- $usersdata["salt"] = substr(md5(uniqid()), 8, 8);
- $usersdata['password'] = pass_hash($usersdata['password'], $usersdata["salt"]);
- } else {
- unset($usersdata['password']);
- }
- if ($registerfield[0]['ptype'] == 'store') {
- $usersdata['sid'] = $res->id;
- }
- if ($registerfield[0]['ptype'] == 'operatingcity') {
- $usersdata['ocid'] = $res->id;
- }
- if ($registerfield[0]['ptype'] == 'tuanzhang') {
- $usersdata['tzid'] = $res->id;
- }
- $usersdata['weid'] = weid();
- $usersdata['uuid'] = $data['uuid'];
- $usersdata['w7uid'] = 0;
- Users::create($usersdata);
- UuidRelation::create(['weid' => weid(), 'ptype' => $registerfield[0]['ptype'], 'uuid' => $res['uuid'], 'uid' => UID()]);
- }
- }
- } catch (\Exception $e) {
- throw new ValidateException($e->getMessage());
- }
- $msg = '提交成功';
- return $this->json(['msg' => $msg, 'data' => $data]);
- }
- }
|