diff --git a/app/api/controller/Identity.php b/app/api/controller/Identity.php index 15176342..6cfb15df 100644 --- a/app/api/controller/Identity.php +++ b/app/api/controller/Identity.php @@ -3,6 +3,8 @@ declare (strict_types=1); namespace app\api\controller; +use app\api\model\user\IdentityOrder; +use app\common\enum\user\IdentityEnum; use cores\exception\BaseException; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; @@ -30,6 +32,38 @@ class Identity extends Controller return $this->renderSuccess(compact('list')); } + /** + * @notes:会员开卡记录 + * @return Json + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function userOpenCardLog(): Json + { + $model = new IdentityOrder(); + $list = $model->cardList(['order_type' => IdentityEnum::MEMBER]); + return $this->renderSuccess($list); + } + + /** + * @notes:分销商开卡记录 + * @return Json + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function dealerOpenCardLog(): Json + { + $model = new IdentityOrder(); + $list = $model->cardList(['order_type' => IdentityEnum::DEALER]); + return $this->renderSuccess($list); + } + /** * @notes:分销身份价格列表 * @return Json diff --git a/app/api/controller/Server.php b/app/api/controller/Server.php index 32b425fd..75e259be 100644 --- a/app/api/controller/Server.php +++ b/app/api/controller/Server.php @@ -47,8 +47,8 @@ class Server extends Controller { $server_name = $this->request->post('server_name'); $category_id = intval($this->request->post('category_id')); - $order_field = $this->request->post('order_field'); - $order_sort = $this->request->post('order_sort', 'desc'); + $order_field = (string)$this->request->post('order_field'); + $order_sort = (string)$this->request->post('order_sort', 'desc'); $where = []; if ($server_name) { $where[] = ['server.server_name', 'like', "%$server_name%"]; @@ -58,7 +58,7 @@ class Server extends Controller } $where[] = ['server.status', '=', 1]; $model = new \app\api\model\Server(); - $list = $model->getList($where, $order_field, $order_sort); + $list = $model->getList($where, 15, $order_field, $order_sort); $data['list'] = $list->items(); $data['total'] = $list->total(); if (!$list->isEmpty()) { @@ -175,6 +175,8 @@ class Server extends Controller 'server_time' => $server_time, 'server_address' => $server_address, 'buyer_remark' => $remake, + 'username' => $username, + 'mobile' => $mobile, ]; $result = $orderService->createOrder($data, $couponId); if ($result) { diff --git a/app/api/model/user/IdentityOrder.php b/app/api/model/user/IdentityOrder.php index 4177f108..e7ac9343 100644 --- a/app/api/model/user/IdentityOrder.php +++ b/app/api/model/user/IdentityOrder.php @@ -3,9 +3,14 @@ namespace app\api\model\user; use app\api\service\User as UserService; +use app\common\enum\order\PayStatus; use app\common\model\user\IdentityOrder as BaseIdentityOrder; use app\common\service\Order as OrderService; use cores\exception\BaseException; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; +use think\model\relation\HasOne; use function getPlatform; class IdentityOrder extends BaseIdentityOrder @@ -63,4 +68,51 @@ class IdentityOrder extends BaseIdentityOrder { return $this->save($data) !== false; } + + public function identity(): HasOne + { + return $this->hasOne(Identity::class, 'identity_id', 'identity_id') + ->bind(['identity_name' => 'name']); + } + + /** + * @notes:开卡记录 + * @param array $where + * @return array + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function cardList(array $where = []): array + { + $userId = UserService::getCurrentLoginUserId(); + $params['user_id'] = $userId; + $params['pay_status'] = PayStatus::SUCCESS; + $where = array_merge($where, $params); + $list = $this->where($where) + ->with(['identity']) + ->order('pay_time', 'desc') + ->limit(20) + ->select(); + $data = []; + if (!empty($list)) { + foreach ($list as $value) { + $end_time = date("Y-m-d", strtotime("+{$value['month']} months", $value['pay_time'])); + $is_valid = false; + if (strtotime(date("Y-m-d")) < strtotime($end_time)) { + $is_valid = true; + } + $data[] = [ + 'start_time' => date("Y-m-d", $value['pay_time']), + 'end_time' => $end_time, + 'name' => $value['identity_name'], + 'month' => $value['month'], + 'is_valid' => $is_valid + ]; + } + } + return $data; + } } \ No newline at end of file diff --git a/app/api/service/Identity.php b/app/api/service/Identity.php index 01398ec4..e7f1b155 100644 --- a/app/api/service/Identity.php +++ b/app/api/service/Identity.php @@ -82,23 +82,12 @@ class Identity extends BaseService private function cheapPrice($data) { - $one_data = []; - foreach ($data as $value) { - if ($value['month'] == 1) { - $one_data = $value; - break; - } - } + $one_data = $data[0]; foreach ($data as $key => $value) { $data[$key]['cheap_price'] = 0; if (!empty($one_data)) { - if ($value['month'] > 1) { - $price = $value['month'] * $one_data['price']; - $data[$key]['cheap_price'] = $price - $value['price']; - } - } else { if ($key > 0) { - $price = $value['month'] * $data[$key - 1]['price']; + $price = $value['month'] * $one_data['price']; $data[$key]['cheap_price'] = $price - $value['price']; } } diff --git a/app/api/service/passport/Login.php b/app/api/service/passport/Login.php index f685ad02..11048c19 100644 --- a/app/api/service/passport/Login.php +++ b/app/api/service/passport/Login.php @@ -191,11 +191,14 @@ class Login extends BaseService // 解密encryptedData -> 拿到手机号 $plainData = OauthService::wxDecryptData($form['encryptedData'], $form['iv'], $wxSession['session_key']); // 整理登录注册数据 + if (empty($form['partyData']['oauth'])) { + $form['partyData']['oauth'] = 'MP-WEIXIN'; + } $loginData = [ 'mobile' => $plainData['purePhoneNumber'], 'isParty' => $form['isParty'], - 'partyData' => !empty($form['partyData']) ?: [], - 'refereeId' => $form['refereeId'] ?? null + 'partyData' => $form['partyData'], + 'refereeId' => $form['refereeId'] ?? null, ]; // 自动登录注册 $this->register($loginData); diff --git a/app/common/model/User.php b/app/common/model/User.php index c375ac52..414aa9df 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -52,9 +52,11 @@ class User extends BaseModel public function getUserTypeTextAttr($value, $data): string { // 身份 - $result = UserTypeEnum::data(); - if (!empty($result[$data['user_type']]['name'])) { - return $result[$data['user_type']]['name']; + if (!empty($data['user_type'])) { + $result = UserTypeEnum::data(); + if (!empty($result[$data['user_type']]['name'])) { + return $result[$data['user_type']]['name']; + } } return '未知'; }