|
@@ -0,0 +1,164 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+// +----------------------------------------------------------------------
|
|
|
|
|
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
|
|
|
|
+// +----------------------------------------------------------------------
|
|
|
|
|
+// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
|
|
|
|
+// +----------------------------------------------------------------------
|
|
|
|
|
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
|
|
|
|
+// +----------------------------------------------------------------------
|
|
|
|
|
+// | Author: CRMEB Team <admin@crmeb.com>
|
|
|
|
|
+// +----------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+namespace app\services\system\store;
|
|
|
|
|
+
|
|
|
|
|
+use app\dao\system\store\SystemStoreRecordDao;
|
|
|
|
|
+use app\services\BaseServices;
|
|
|
|
|
+use crmeb\exceptions\AdminException;
|
|
|
|
|
+use app\services\system\store\SystemStoreServices;
|
|
|
|
|
+use app\services\system\store\SystemStoreStaffServices;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 门店申请记录服务
|
|
|
|
|
+ * Class SystemStoreRecordServices
|
|
|
|
|
+ * @package app\services\system\store
|
|
|
|
|
+ */
|
|
|
|
|
+class SystemStoreRecordServices extends BaseServices
|
|
|
|
|
+{
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 构造方法
|
|
|
|
|
+ * SystemStoreRecordServices constructor.
|
|
|
|
|
+ * @param SystemStoreRecordDao $dao
|
|
|
|
|
+ */
|
|
|
|
|
+ public function __construct(SystemStoreRecordDao $dao)
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->dao = $dao;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取门店申请列表
|
|
|
|
|
+ * @param array $where
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getApplyList(array $where)
|
|
|
|
|
+ {
|
|
|
|
|
+ $searchWhere = [];
|
|
|
|
|
+ if (isset($where['keywords']) && $where['keywords'] !== '') {
|
|
|
|
|
+ $searchWhere[] = ['name|phone', 'like', '%' . $where['keywords'] . '%'];
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isset($where['status']) && $where['status'] !== '') {
|
|
|
|
|
+ $searchWhere['status'] = $where['status'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [$page, $limit] = $this->getPageValue();
|
|
|
|
|
+ $list = $this->dao->getApplyList($searchWhere, $page, $limit);
|
|
|
|
|
+ $count = $this->dao->count($searchWhere);
|
|
|
|
|
+
|
|
|
|
|
+ return compact('list', 'count');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 通过门店申请
|
|
|
|
|
+ * @param int $id
|
|
|
|
|
+ * @return bool
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function approve(int $id)
|
|
|
|
|
+ {
|
|
|
|
|
+ $recordInfo = $this->dao->getApplyInfo($id);
|
|
|
|
|
+ if (!$recordInfo) {
|
|
|
|
|
+ throw new AdminException('申请记录不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($recordInfo['status'] != 0) {
|
|
|
|
|
+ throw new AdminException('该申请已审核');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $this->transaction(function () use ($recordInfo, $id) {
|
|
|
|
|
+ // 更新申请状态为通过
|
|
|
|
|
+ $res = $this->dao->update($id, ['status' => 1]);
|
|
|
|
|
+ if (!$res) {
|
|
|
|
|
+ throw new AdminException('审核失败');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 创建正式门店记录
|
|
|
|
|
+ $storeServices = app()->make(SystemStoreServices::class);
|
|
|
|
|
+ $storeData = [
|
|
|
|
|
+ 'name' => $recordInfo['name'],
|
|
|
|
|
+ 'phone' => $recordInfo['phone'],
|
|
|
|
|
+ 'address' => $recordInfo['address'],
|
|
|
|
|
+ 'detailed_address' => $recordInfo['detailed_address'],
|
|
|
|
|
+ 'latlng' => $recordInfo['latlng'],
|
|
|
|
|
+ 'latitude' => $recordInfo['latitude'],
|
|
|
|
|
+ 'longitude' => $recordInfo['longitude'],
|
|
|
|
|
+ 'day_time' => $recordInfo['day_time'],
|
|
|
|
|
+ 'valid_time' => $recordInfo['valid_time'],
|
|
|
|
|
+ 'image' => $recordInfo['image'],
|
|
|
|
|
+ 'uid' => $recordInfo['uid'],
|
|
|
|
|
+ 'is_show' => 1,
|
|
|
|
|
+ 'add_time' => time(),
|
|
|
|
|
+ ];
|
|
|
|
|
+ $storeId = $storeServices->save($storeData);
|
|
|
|
|
+
|
|
|
|
|
+ if (!$storeId) {
|
|
|
|
|
+ throw new AdminException('创建门店失败');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 添加用户为店员
|
|
|
|
|
+ $staffServices = app()->make(SystemStoreStaffServices::class);
|
|
|
|
|
+ $userServices = app()->make(\app\services\user\UserServices::class);
|
|
|
|
|
+
|
|
|
|
|
+ // 检查该用户是否已经是店员
|
|
|
|
|
+ if (!$staffServices->count(['uid' => $recordInfo['uid']])) {
|
|
|
|
|
+ // 从user表获取店员的image和staff_name
|
|
|
|
|
+ $userInfo = $userServices->getUserInfo($recordInfo['uid']);
|
|
|
|
|
+
|
|
|
|
|
+ $staffData = [
|
|
|
|
|
+ 'uid' => $recordInfo['uid'],
|
|
|
|
|
+ 'store_id' => $storeId,
|
|
|
|
|
+ 'staff_name' => $userInfo['nickname'] ?? '',
|
|
|
|
|
+ 'avatar' => $userInfo['avatar'] ?? ($userInfo['image'] ?? ''),
|
|
|
|
|
+ 'phone' => $recordInfo['phone'],
|
|
|
|
|
+ 'verify_status' => 1,
|
|
|
|
|
+ 'status' => 1,
|
|
|
|
|
+ 'add_time' => time(),
|
|
|
|
|
+ ];
|
|
|
|
|
+ $staffServices->save($staffData);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 拒绝门店申请
|
|
|
|
|
+ * @param int $id
|
|
|
|
|
+ * @return bool
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function reject(int $id)
|
|
|
|
|
+ {
|
|
|
|
|
+ $recordInfo = $this->dao->getApplyInfo($id);
|
|
|
|
|
+ if (!$recordInfo) {
|
|
|
|
|
+ throw new AdminException('申请记录不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($recordInfo['status'] != 0) {
|
|
|
|
|
+ throw new AdminException('该申请已审核');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 更新申请状态为拒绝
|
|
|
|
|
+ $res = $this->dao->update($id, ['status' => 2]);
|
|
|
|
|
+ if (!$res) {
|
|
|
|
|
+ throw new AdminException('审核失败');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|