|
@@ -0,0 +1,113 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace app\admin\controller\customer;
|
|
|
|
+
|
|
|
|
+use app\controller\Curd;
|
|
|
|
+use app\model\Customer;
|
|
|
|
+use app\model\Member;
|
|
|
|
+use app\model\MemberCert;
|
|
|
|
+use app\model\MemberInfo;
|
|
|
|
+use app\model\SysSerial;
|
|
|
|
+use support\Db;
|
|
|
|
+use support\exception\BusinessException;
|
|
|
|
+use support\Request;
|
|
|
|
+use Tinywan\Jwt\JwtToken;
|
|
|
|
+
|
|
|
|
+class IndexController extends Curd
|
|
|
|
+{
|
|
|
|
+ public function __construct()
|
|
|
|
+ {
|
|
|
|
+ $this->model = new Customer();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected function afterQuery($items)
|
|
|
|
+ {
|
|
|
|
+ foreach ($items as &$item) {
|
|
|
|
+ $item->city = explode(',', $item->city);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $items;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected function insertInput(Request $request): array
|
|
|
|
+ {
|
|
|
|
+ $data = $this->inputFilter($request->post());
|
|
|
|
+ $data['creator'] = JwtToken::getCurrentId();
|
|
|
|
+ if (!empty($data['birth'])) {
|
|
|
|
+ $data['birth'] = date('Y-m-d', strtotime($data['birth']));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected function updateInput(Request $request): array
|
|
|
|
+ {
|
|
|
|
+ $primary_key = $this->model->getKeyName();
|
|
|
|
+ $id = $request->post($primary_key);
|
|
|
|
+ $data = $this->inputFilter($request->post());
|
|
|
|
+ if (!empty($data['birth'])) {
|
|
|
|
+ $data['birth'] = date('Y-m-d', strtotime($data['birth']));
|
|
|
|
+ }
|
|
|
|
+ $model = $this->model->find($id);
|
|
|
|
+ if (!$model) {
|
|
|
|
+ throw new BusinessException('记录不存在', 2);
|
|
|
|
+ }
|
|
|
|
+ unset($data[$primary_key]);
|
|
|
|
+ return [$id, $data];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function conversion(Request $request)
|
|
|
|
+ {
|
|
|
|
+ $id = $request->post('id');
|
|
|
|
+ $customer = Customer::where('id', $id)->first();
|
|
|
|
+ if (!$customer) {
|
|
|
|
+ return json_fail('客户不存在');
|
|
|
|
+ }
|
|
|
|
+ Db::beginTransaction();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ $memberId = "ME" . str_pad(SysSerial::getSerial(), 16, "0", STR_PAD_LEFT) . random_string(6, 'up');
|
|
|
|
+ $member = [
|
|
|
|
+ 'member_id' => $memberId,
|
|
|
|
+ 'member_is_owner' => 'N',
|
|
|
|
+ 'member_classify' => 'MEMBER',
|
|
|
|
+ 'member_status' => 'ACTIVED',
|
|
|
|
+ 'member_mobile' => $customer->mobile ?? '',
|
|
|
|
+ 'member_from' => 'CUSTOMER',
|
|
|
|
+ 'member_addtimes'=>time()
|
|
|
|
+ ];
|
|
|
|
+ Member::insert($member);
|
|
|
|
+
|
|
|
|
+ // cert
|
|
|
|
+ $cert = [
|
|
|
|
+ 'join_cert_member_id' => $memberId,
|
|
|
|
+ 'member_cert_name' => $customer->name,
|
|
|
|
+ 'member_cert_nbr' => $customer->card_id ?? '',
|
|
|
|
+ 'member_cert_birth' => $customer->birth ?? '',
|
|
|
|
+ 'member_cert_gender' => $customer->gender ?? '',
|
|
|
|
+ 'member_cert_province' => $customer->city ?? '',
|
|
|
|
+ 'member_cert_addr' => $customer->address ?? ''
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ MemberCert::insert($cert);
|
|
|
|
+
|
|
|
|
+ // info
|
|
|
|
+ $info = [
|
|
|
|
+ 'join_info_member_id' => $memberId,
|
|
|
|
+ 'member_info_nickname' => $customer->name
|
|
|
|
+ ];
|
|
|
|
+ MemberInfo::insert($info);
|
|
|
|
+
|
|
|
|
+ $customer->status = '正式用户';
|
|
|
|
+ $customer->save();
|
|
|
|
+
|
|
|
|
+ Db::commit();
|
|
|
|
+
|
|
|
|
+ return json_success("转正式用户成功");
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
+ dump($e->getMessage());
|
|
|
|
+ Db::rollBack();
|
|
|
|
+ return json_fail('转正式用户失败');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|