v1.0
parent
b2be5c5533
commit
96c7082f32
@ -0,0 +1,114 @@ |
||||
<?php |
||||
|
||||
namespace app\store\controller\wholesaler; |
||||
|
||||
use app\common\enum\user\UserTypeEnum; |
||||
use app\common\enum\WholesalerEnum; |
||||
use app\common\model\User as UserModel; |
||||
use app\store\controller\Controller; |
||||
use DateInterval; |
||||
use DateTime; |
||||
use Exception; |
||||
use think\db\exception\DbException; |
||||
use think\response\Json; |
||||
|
||||
class Apply extends Controller |
||||
{ |
||||
/** |
||||
* @notes:订单状态 |
||||
* @return Json |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function applyStatus(): Json |
||||
{ |
||||
$list = array_values(WholesalerEnum::data()); |
||||
return $this->renderSuccess(compact('list')); |
||||
} |
||||
|
||||
/** |
||||
* @notes:申请记录 |
||||
* @return Json |
||||
* @throws DbException |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function list(): Json |
||||
{ |
||||
$username = $this->request->post('username'); |
||||
$mobile = $this->request->post('mobile'); |
||||
$company_name = $this->request->post('company_name'); |
||||
$status = intval($this->request->post('status')); |
||||
$where = []; |
||||
if (!empty($username)) { |
||||
$where[] = ['username', 'like', "%$username%"]; |
||||
} |
||||
if (!empty($company_name)) { |
||||
$where[] = ['company_name', 'like', "%$company_name%"]; |
||||
} |
||||
if (!empty($mobile)) { |
||||
$where[] = ['mobile', 'like', "%$mobile%"]; |
||||
} |
||||
if ($status) { |
||||
$where[] = ['status', '=', $status]; |
||||
} |
||||
$model = new \app\store\model\wholesaler\Apply(); |
||||
$list = $model->where($where) |
||||
->with(['user']) |
||||
->order('id', 'desc') |
||||
->paginate(15); |
||||
$data['list'] = $list->items(); |
||||
$data['total'] = $list->total(); |
||||
return $this->renderSuccess($data); |
||||
} |
||||
|
||||
public function detail(): Json |
||||
{ |
||||
$id = intval($this->request->post('id')); |
||||
$info = \app\store\model\wholesaler\Apply::detail(['id' => $id], ['cardFrontImg', 'cardBackImg', 'licenseImg', 'doorImg', 'user']); |
||||
return $this->renderSuccess(compact('info')); |
||||
} |
||||
|
||||
/** |
||||
* @notes:审核 |
||||
* @return Json |
||||
* @throws Exception |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function audit(): Json |
||||
{ |
||||
$id = intval($this->request->post('id')); |
||||
if (!$id) { |
||||
return $this->renderError('非法请求'); |
||||
} |
||||
$status = intval($this->request->post('status')); |
||||
if (!$status) { |
||||
return $this->renderError('非法请求'); |
||||
} |
||||
$remake = $this->request->post('remake'); |
||||
if ($status == WholesalerEnum::REFUSE && !$remake) { |
||||
return $this->renderError('驳回原因不能为空'); |
||||
} |
||||
$info = \app\store\model\wholesaler\Apply::detail(['id' => $id]); |
||||
if (empty($info)) { |
||||
return $this->renderError('数据异常'); |
||||
} |
||||
$info = $info->toArray(); |
||||
if ($info['status'] != WholesalerEnum::AUDITING) { |
||||
return $this->renderError('非法操作'); |
||||
} |
||||
//更新记录 |
||||
$model = new \app\store\model\wholesaler\Apply(); |
||||
$model->transaction(function () use ($status, $remake, $info, $model) { |
||||
$model->where(['id' => $info['id']])->update(['status' => $status, 'remake' => $remake]); |
||||
//通过开通采购商会员 |
||||
if ($status == WholesalerEnum::ADOPT) { |
||||
$date = new DateTime(date('Y-m-d')); |
||||
$date->add(new DateInterval("P{$info['year']}Y")); |
||||
$up['effective_time'] = $date->format('Y-m-d'); |
||||
$up['user_type'] = UserTypeEnum::MEMBER; |
||||
$userModel = new UserModel(); |
||||
$userModel->where(['user_id' => $info['user_id']])->save($up); |
||||
} |
||||
}); |
||||
return $this->renderSuccess('操作成功'); |
||||
} |
||||
} |
@ -0,0 +1,8 @@ |
||||
<?php |
||||
|
||||
namespace app\store\model\wholesaler; |
||||
|
||||
class Apply extends \app\common\model\wholesaler\Apply |
||||
{ |
||||
|
||||
} |
Loading…
Reference in new issue