ShopApplyService.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\service\api\shop;
  3. use app\dict\shop\ShopApplyDict;
  4. use app\model\shop\ShopApply;
  5. use core\base\BaseApiService;
  6. use core\exception\ApiException;
  7. /**
  8. * 店铺申请服务层
  9. * Class ShopApplyService
  10. * @package addon\mall\app\service\api\shop
  11. */
  12. class ShopApplyService extends BaseApiService
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. $this->model = new ShopApply();
  18. }
  19. /**
  20. * 店铺申请列表
  21. * @param array $where
  22. * @return array
  23. */
  24. public function getPage(array $where = [])
  25. {
  26. $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';
  27. $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');
  28. return $this->pageQuery($search_model);
  29. }
  30. /**
  31. * 店铺申请详情
  32. * @param int $id
  33. * @return array
  34. */
  35. public function getInfo(int $id)
  36. {
  37. $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';
  38. $info = $this->model->field($field)->with([ 'memberName', 'shopCategoryName', 'siteGroupName' ])->append([ 'status_name' ])->where([ [ 'apply_id', '=', $id ] ])->findOrEmpty()->toArray();
  39. return $info;
  40. }
  41. /**
  42. * 添加店铺申请
  43. * @param array $data
  44. * @return mixed
  45. */
  46. public function add(array $data)
  47. {
  48. $apply_info = $this->model->where([ [ 'member_id', '=', $this->member_id ], [ 'status', 'in', [ShopApplyDict::WAIT_AUDIT, ShopApplyDict::PASS] ] ])->findOrEmpty()->toArray();
  49. if(!empty($apply_info)) throw new ApiException('SHOP_APPLY_PASS_OR_WAIT_AUDIT');
  50. $data['create_time'] = time();
  51. $data['member_id'] = $this->member_id;
  52. $res = $this->model->create($data);
  53. return $res->apply_id;
  54. }
  55. /**
  56. * 编辑店铺申请
  57. * @param int $id
  58. * @param array $data
  59. * @return bool
  60. */
  61. public function edit(int $id, array $data)
  62. {
  63. $apply_info = $this->model->where([ [ 'member_id', '=', $this->member_id ], [ 'status', 'in', [ShopApplyDict::WAIT_AUDIT, ShopApplyDict::PASS] ] ])->findOrEmpty()->toArray();
  64. if(!empty($apply_info)) throw new ApiException('SHOP_APPLY_PASS_OR_WAIT_AUDIT');
  65. $shop_apply = $this->model->where([ [ 'apply_id', '=', $id ] ])->findOrEmpty()->toArray();
  66. if(empty($shop_apply)) throw new ApiException('SHOP_APPLY_NOT_EXIT');
  67. $data[ 'update_time' ] = time();
  68. $data[ 'refuse_reason' ] = '';
  69. $this->model->where([ [ 'apply_id', '=', $id ] ])->update($data);
  70. return true;
  71. }
  72. /**
  73. * 获取店铺申请状态
  74. * @return array
  75. */
  76. public function getStatusList()
  77. {
  78. $list = [];
  79. $status = ShopApplyDict::getStatus();
  80. foreach ($status as $k => $v) {
  81. $list[] = [
  82. 'label' => $v,
  83. 'value' => $k,
  84. ];
  85. }
  86. return $list;
  87. }
  88. }