12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace app\service\api\shop;
- use app\dict\shop\ShopApplyDict;
- use app\model\shop\ShopApply;
- use core\base\BaseApiService;
- use core\exception\ApiException;
- class ShopApplyService extends BaseApiService
- {
- public function __construct()
- {
- parent::__construct();
- $this->model = new ShopApply();
- }
-
- public function getPage(array $where = [])
- {
- $field = 'apply_id, member_id, site_name, user_name, user_mobile, category_id, group_id, business_license, status, create_time, update_time, audit_time, refuse_reason';
- $search_model = $this->model->where([ ['member_id', '=', $this->member_id] ])->withSearch([ 'status' ], $where)->with([ 'memberName', 'shopCategoryName', 'siteGroupName' ])->append([ 'status_name' ])->field($field)->order('create_time desc');
- return $this->pageQuery($search_model);
- }
-
- public function getInfo(int $id)
- {
- $field = 'apply_id, member_id, site_name, user_name, user_mobile, category_id, group_id, business_license, status, create_time, update_time, audit_time, refuse_reason';
- $info = $this->model->field($field)->with([ 'memberName', 'shopCategoryName', 'siteGroupName' ])->append([ 'status_name' ])->where([ [ 'apply_id', '=', $id ] ])->findOrEmpty()->toArray();
- return $info;
- }
-
- public function add(array $data)
- {
- $apply_info = $this->model->where([ [ 'member_id', '=', $this->member_id ], [ 'status', 'in', [ShopApplyDict::WAIT_AUDIT, ShopApplyDict::PASS] ] ])->findOrEmpty()->toArray();
- if(!empty($apply_info)) throw new ApiException('SHOP_APPLY_PASS_OR_WAIT_AUDIT');
- $data['create_time'] = time();
- $data['member_id'] = $this->member_id;
- $res = $this->model->create($data);
- return $res->apply_id;
- }
-
- public function edit(int $id, array $data)
- {
- $apply_info = $this->model->where([ [ 'member_id', '=', $this->member_id ], [ 'status', 'in', [ShopApplyDict::WAIT_AUDIT, ShopApplyDict::PASS] ] ])->findOrEmpty()->toArray();
- if(!empty($apply_info)) throw new ApiException('SHOP_APPLY_PASS_OR_WAIT_AUDIT');
- $shop_apply = $this->model->where([ [ 'apply_id', '=', $id ] ])->findOrEmpty()->toArray();
- if(empty($shop_apply)) throw new ApiException('SHOP_APPLY_NOT_EXIT');
- $data[ 'update_time' ] = time();
- $data[ 'refuse_reason' ] = '';
- $this->model->where([ [ 'apply_id', '=', $id ] ])->update($data);
- return true;
- }
-
- public function getStatusList()
- {
- $list = [];
- $status = ShopApplyDict::getStatus();
- foreach ($status as $k => $v) {
- $list[] = [
- 'label' => $v,
- 'value' => $k,
- ];
- }
- return $list;
- }
- }
|