链街Dcat后台
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.

192 lines
6.7 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Extensions\CheckRow;
  4. use App\Admin\Repositories\LanzuMpInfo;
  5. use App\Models\LanzuMmInfo as mmInfo;
  6. use App\Models\MpBalance;
  7. use Dcat\Admin\Actions\Action;
  8. use Dcat\Admin\Admin;
  9. use Dcat\Admin\Form;
  10. use Dcat\Admin\Grid;
  11. use Dcat\Admin\Show;
  12. use Dcat\Admin\Controllers\AdminController;
  13. use EasyWeChat\Factory;
  14. use Encore\Admin\Grid\Displayers\Actions;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Support\Facades\Hash;
  17. use \App\Models\LanzuMpInfo as mpInfo;
  18. use \App\Models\AdminUsers;
  19. use \App\Models\AdminRoles;
  20. use \App\Models\AdminRoleUsers;
  21. class LanzuMpInfoController extends AdminController
  22. {
  23. /**
  24. * Make a grid builder.
  25. *
  26. * @return Grid
  27. */
  28. protected function grid()
  29. {
  30. return Grid::make(new LanzuMpInfo(), function (Grid $grid) {
  31. $grid->name;
  32. $grid->phone;
  33. $grid->actions(function (Grid\Displayers\Actions $actions) {
  34. $actions->row->id;
  35. });
  36. $grid->column('可提现金额')->display(function () {
  37. return MpBalance::getBalance($this->id, 1);
  38. });
  39. $grid->id_frond->image('', 50, 50);
  40. $grid->id_back->image('', 50, 50);
  41. $grid->id_number;
  42. $grid->column('status', '状态')->display(function ($status) {
  43. if ($status == 1) {
  44. return '正常';
  45. } elseif ($status == 0) {
  46. return '禁用';
  47. }
  48. });
  49. $grid->created_at->display(function ($time) {
  50. return date("Y-m-d H:i", $time);
  51. });
  52. $grid->filter(function (Grid\Filter $filter) {
  53. $filter->equal('id');
  54. });
  55. $grid->filter(function (Grid\Filter $filter) {
  56. $filter->like('name');
  57. });
  58. });
  59. }
  60. public function test()
  61. {
  62. $config = [
  63. // 必要配置
  64. 'app_id' => 'wxf66ed55b54d7f942',
  65. 'mch_id' => '1536995001',
  66. 'key' => 'lazywisdom8888888888888888888888', // API 密钥
  67. // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
  68. 'cert_path' => './certs/apiclient_cert.pem', // XXX: 绝对路径!!!!
  69. 'key_path' => './certs/apiclient_key.pem', // XXX: 绝对路径!!!!
  70. 'notify_url' => '默认的订单回调地址', // 你也可以在下单时单独设置来想覆盖它
  71. ];
  72. $app = Factory::payment($config);
  73. $res = $app->transfer->toBalance([
  74. 'partner_trade_no' => '1233455', // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
  75. 'openid' => 'ojbLs4otqY74RjlVHLlywoaLS5t8',
  76. 'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
  77. 're_user_name' => '王小帅', // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
  78. 'amount' => 30, // 企业付款金额,单位为分
  79. 'desc' => '测试', // 企业付款操作说明信息。必填
  80. ]);
  81. dd($res);
  82. }
  83. /**
  84. * Make a show builder.
  85. *
  86. * @param mixed $id
  87. *
  88. * @return Show
  89. */
  90. protected function detail($id)
  91. {
  92. return Show::make($id, new LanzuMpInfo(), function (Show $show) {
  93. $show->id;
  94. $show->name;
  95. $show->phone;
  96. $show->bank_name;
  97. $show->bank_card;
  98. $show->bank_addr;
  99. $show->id_frond;
  100. $show->id_back;
  101. $show->id_number;
  102. $show->admin_user_id;
  103. $show->status;
  104. $show->created_at;
  105. $show->updated_at;
  106. });
  107. }
  108. /**
  109. * Make a form builder.
  110. *
  111. * @return Form
  112. */
  113. protected function form()
  114. {
  115. return Form::make(new LanzuMpInfo(), function (Form $form) {
  116. $form->display('id')->hideInDialog();
  117. $form->text('name', '姓名')->required();
  118. $form->mobile('phone')->required();
  119. $form->text('bank_name')->required();
  120. $form->text('bank_card')->required();
  121. $form->text('bank_addr')->required();
  122. $form->image('id_frond')->uniqueName()->required();
  123. $form->image('id_back')->uniqueName()->required();
  124. $form->text('id_number')->required();
  125. $form->radio('status', '状态')->options(['禁用', '启用'])->default(1);
  126. $form->saved(function (Form $form, $result) {
  127. $adu = new AdminUsers();
  128. if ($form->isCreating()) {
  129. $newId = $result;
  130. if (!$newId) {
  131. return $form->error('服务商添加失败');
  132. }
  133. $mp = mpInfo::find($newId);
  134. //>>1.添加服务商,前去查询是否已存在相同的帐号
  135. $count = $adu->where(['username' => $form->phone])->count();
  136. if ($count) {
  137. $mp->delete();
  138. return $form->error('该手机号作为登陆帐号已存在!');
  139. }
  140. //>>2.添加服务商登陆帐号
  141. $adu->username = $form->phone;
  142. $adu->password = Hash::make(substr($form->phone, -5));
  143. $adu->name = $form->name;
  144. $adu->status = $form->status;
  145. $res = $adu->save();
  146. if (!$res) {
  147. //删除刚添加的服务商
  148. $mp->delete();
  149. return $form->error('服务商添加失败');
  150. }
  151. //>>3.将帐号id关联到服务商
  152. $mp->admin_user_id = $adu->id;
  153. $mp->save();
  154. //添加服务商角色
  155. $lanzu_mp = AdminRoles::where('slug', 'lanzu_mp')->first();
  156. $aru = new AdminRoleUsers;
  157. $aru->role_id = $lanzu_mp->id;
  158. $aru->user_id = $adu->id;
  159. $aru->save();
  160. } else {
  161. //>>4.编辑时同步登陆帐号状态
  162. $id = $form->getKey();
  163. $mp = mpInfo::find($id);
  164. $ad = $adu->find($mp->admin_user_id);
  165. $ad->status = $form->status;
  166. $ad->save();
  167. }
  168. });
  169. });
  170. }
  171. }