海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

249 lines
9.4 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Extensions\Grid\AuditAgent;
  4. use App\Admin\Repositories\Agent;
  5. use App\Common\AgentType;
  6. use App\Common\UserStatus;
  7. use App\Models\Supplier;
  8. use Dcat\Admin\Form;
  9. use Dcat\Admin\Grid;
  10. use Dcat\Admin\Show;
  11. use Dcat\Admin\Http\Controllers\AdminController;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Support\Facades\Route;
  14. class AgentController extends AdminController
  15. {
  16. /**
  17. * Make a grid builder.
  18. *
  19. * @return Grid
  20. */
  21. protected function grid()
  22. {
  23. return Grid::make(new Agent(['miniUpload', 'settledOrder']), function (Grid $grid) {
  24. $grid->disableDeleteButton();
  25. $grid->disableRowSelector();
  26. //如果是审核页面,多加where条件判断
  27. if (strpos(Route::current()->uri, 'audit')) {
  28. $grid->model()->where('status', UserStatus::UNAUDITED);
  29. }
  30. $grid->model()->where('id', '>', 1); //隐藏ID=1的领峰云管理员
  31. $grid->column('id')->sortable();
  32. $grid->column('username');
  33. $grid->column('type')->using(AgentType::array());
  34. $grid->column('company_name');
  35. $grid->column('对公账号')->display(fn() => $this->corporate_account . ' / ' . $this->deposit_bank)->limit(15);
  36. $grid->column('license')->image('', 60, 60);
  37. $grid->column('business_license')->image('', 60, 60);
  38. $grid->column('director');
  39. $grid->column('contact_phone');
  40. $grid->column('cost', '入驻费')
  41. ->help('该代理商已支付的入驻费(入驻时微信支付的费用)')
  42. ->if(fn() => !empty($this->settledOrder->paid_money) && floatval($this->settledOrder->paid_money) != 0)
  43. ->display(fn() => $this->settledOrder->paid_money ?? 0)->label('success');
  44. $grid->column('created_at');
  45. $grid->column('status', '状态')
  46. ->using(UserStatus::array())
  47. ->dot([
  48. UserStatus::NORMAL => 'success',
  49. UserStatus::UNAUDITED => '',
  50. UserStatus::REFUSE => 'danger',
  51. UserStatus::DISABLED => 'warning',
  52. ], 'primary')
  53. ->if(fn() => $this->status == UserStatus::UNAUDITED)
  54. ->display('')
  55. ->then(function ($column) {
  56. $column->append((new AuditAgent(null, 1))->setKey($this->id))->append('&nbsp;');
  57. $column->append((new AuditAgent(null, 2))->setKey($this->id));
  58. });
  59. $grid->filter(function (Grid\Filter $filter) {
  60. $filter->panel();
  61. $filter->equal('id')->width(2);
  62. $filter->like('company_name')->width(3);
  63. $filter->equal('status', '用户状态')->select(UserStatus::array())->width(2);
  64. });
  65. });
  66. }
  67. /**
  68. * Make a show builder.
  69. *
  70. * @param mixed $id
  71. *
  72. * @return Show
  73. */
  74. protected function detail($id)
  75. {
  76. return Show::make($id, new Agent('agentInfo'), function (Show $show) {
  77. $show->disableDeleteButton();
  78. $show->field('id');
  79. $show->field('username');
  80. $show->field('name');
  81. $show->field('appid');
  82. // $show->field('appsecret');
  83. // $show->field('mchid');
  84. // $show->field('mchkey');
  85. $show->field('status')->using(UserStatus::array());
  86. $show->field('type')->using(AgentType::array());
  87. $show->field('company_name');
  88. $show->field('address');
  89. $show->field('credit_codes');
  90. $show->field('license')->image('', 80, 80);
  91. $show->field('business_license')->image('', 80, 80);
  92. $show->field('director');
  93. $show->field('contact_phone');
  94. $show->field('legal_persona_name');
  95. $show->field('legal_persona_wechat');
  96. //$show->field('rate');
  97. $show->field('agentInfo.about', '关于我们')
  98. ->unescape()
  99. ->as(function ($v) {
  100. return preg_replace('/<script.*?>.*?<\/script>/is', '', $this->agentInfo->about ?? '');
  101. });
  102. $show->field('agentInfo.reg_protocol', '注册协议')
  103. ->unescape()
  104. ->as(function ($v) {
  105. return preg_replace('/<script.*?>.*?<\/script>/is', '', $this->agentInfo->reg_protocol ?? '');
  106. });
  107. $show->field('agentInfo.buy_protocol', '购买协议')
  108. ->unescape()
  109. ->as(function ($v) {
  110. return preg_replace('/<script.*?>.*?<\/script>/is', '', $this->agentInfo->buy_protocol ?? '');
  111. });
  112. $show->field('corporate_account');
  113. $show->field('deposit_bank');
  114. $show->field('contract')->image('', 60, 60);
  115. $show->field('created_at');
  116. $show->field('updated_at');
  117. });
  118. }
  119. /**
  120. * Make a form builder.
  121. *
  122. * @return Form
  123. */
  124. protected function form()
  125. {
  126. return Form::make(new Agent('agentInfo'), function (Form $form) {
  127. $form->disableDeleteButton();
  128. $form->display('id');
  129. //新增
  130. if ($form->isCreating()) {
  131. $form->text('username')->required();
  132. $form->text('password')->required();
  133. }
  134. else if ($form->isEditing()) {
  135. $form->display('username');
  136. $form->text('password')->customFormat(fn() => '');
  137. }
  138. $form->text('name')->required();
  139. $form->display('appid')->help('无需填写,注册小程序后会自动生成');
  140. // $form->text('appsecret')->help('无需填写,注册小程序后会自动生成');
  141. // $form->text('mchid')->required();
  142. // $form->text('mchkey')->required();
  143. $form->select('status')
  144. ->default(UserStatus::NORMAL)
  145. ->options(UserStatus::array())
  146. ->required();
  147. $form->radio('type')
  148. ->options(AgentType::array())
  149. ->default(AgentType::OPERATOR)
  150. ->required();
  151. $form->text('company_name')->required()->help('请正确填写,保持跟营业执照上的完全一致,如:海南易游天下供应链有限公司');
  152. $form->text('credit_codes')->required()->help('请正确填写,保持跟营业执照上的完全一致,如:91440300577652919M');
  153. $form->text('address');
  154. $form->distpicker(['province_id', 'city_id', 'area_id'], '请选择区域')->required();
  155. $form->multipleImage('license')->removable(false)->uniqueName();
  156. $form->image('business_license')->removable(false)->uniqueName();
  157. $form->text('director');
  158. $form->text('contact_phone');
  159. $form->text('legal_persona_name')->required()->maxLength(20)->help('很重要,注册小程序时需要用到,用于实名认证');
  160. $form->text('legal_persona_wechat')->required()->maxLength(100)->help('很重要,用于接收实名认证信息,不能是手机号或QQ号,微信号请前往微信“我的”页面查看');
  161. //$form->number('rate')->min(0)->max(100)->help('分成百分比,如10%,则输入10');
  162. $form->editor('agentInfo.about', '关于我们');// 隐藏菜单用:->options(['menubar' => false]);
  163. $form->editor('agentInfo.reg_protocol', '注册协议');
  164. $form->editor('agentInfo.buy_protocol', '购买协议');
  165. })->saving(function (Form $form) {
  166. //判断账号是否唯一
  167. if ($form->isCreating()) {
  168. if ($form->repository()->model()->where('username', $form->username)->exists()) {
  169. return $form->response()->error($form->username . ' 的账号已经存在');
  170. }
  171. }
  172. ////抽成比例
  173. //if ($form->rate < 0 || $form->rate > 100) {
  174. // return $form->response()->error('抽成比例在 0 ~ 100 之间');
  175. //}
  176. //不允许编辑的字段
  177. if ($form->isEditing()) {
  178. $form->ignore(['id', 'username', 'created_at', 'updated_at', 'deleted_at']);
  179. }
  180. //过滤null字段
  181. $allow_null = ['avatar', 'remember_token', 'appid', 'appsecret', 'mchid', 'mchkey'];
  182. foreach($form->input() as $k => $v) {
  183. if (is_null($v) && !in_array($k, $allow_null)) {
  184. $form->$k = '';
  185. } else if (is_array($v)) {
  186. foreach ($v as $k2 => &$v2) {
  187. if (is_null($v2)) {
  188. $v2 = ''; //不能用$form->$k[$k2] = '',会报错,只能通过引用修改
  189. } else {
  190. $v2 = preg_replace('/<script.*?>.*?<\/script>/is', '', $v2);
  191. }
  192. }
  193. }
  194. }
  195. })->saved(function (Form $form, $result) {
  196. //如果状态是正常,插入初始数据
  197. if ($result && $form->status == UserStatus::NORMAL) {
  198. (new AuditAgent)->setKey($form->getKey())->pass();
  199. //如果是供应商版旅行社,同时插入供应商会员表
  200. if ($form->type == AgentType::SUPPLIER) {
  201. if (Supplier::query()->where('username', $form->model()->username)->doesntExist()) {
  202. DB::beginTransaction();
  203. try {
  204. //插入用户表
  205. $supplier_id = Supplier::query()->insertGetId([
  206. 'username' => $form->model()->username,
  207. 'password' => $form->model()->password, //密码不用转换,原样插入
  208. 'name' => $form->model()->name,
  209. 'avatar' => $form->model()->avatar,
  210. 'status' => $form->model()->status,
  211. 'company_name' => $form->model()->company_name,
  212. 'logo' => $form->model()->logo,
  213. 'license' => $form->model()->license,
  214. 'address' => $form->model()->address,
  215. 'business_license' => $form->model()->business_license,
  216. 'director' => $form->model()->director,
  217. 'contact_phone' => $form->model()->contact_phone,
  218. //'rate' => $form->model()->password,
  219. ]);
  220. //插入权限表
  221. DB::table(config('admin-supplier.database.role_users_table'))
  222. ->insertOrIgnore(['role_id' => 2, 'user_id' => $supplier_id]);
  223. DB::commit();
  224. } catch (\Exception $e) {
  225. DB::rollBack();
  226. return $form->response()->error('保存成功,但插入供应商会员失败,失败为:' . $e->getMessage());
  227. }
  228. }
  229. }
  230. }
  231. });
  232. }
  233. }