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/model/user/IdentityOrder.php b/app/api/model/user/IdentityOrder.php index 4177f108..10bdbe0e 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,44 @@ 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) { + $data[] = [ + 'start_time' => date("Y-m-d", $value['pay_time']), + 'end_time' => date("Y-m-d", strtotime("+{$value['month']} months", $value['pay_time'])), + 'name' => $value['identity_name'], + ]; + } + } + return $data; + } } \ No newline at end of file