海南旅游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.

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