链街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.

216 lines
7.2 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
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\v3;
  3. use App\Admin\Repositories\v3\Store;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Controllers\AdminController;
  8. use App\Models\LanzuMmInfo as MminfoModel;
  9. use App\Models\v3\Market as MarketModel;
  10. use App\Admin\Common\StoreQRCode;
  11. use App\Models\v3\Store as StoreModel;
  12. use App\Models\v3\User as UserModel;
  13. use App\Models\v3\Category as CategoryModel;
  14. use App\Models\LanzuUserBalance as UserBalanceModel;
  15. class StoreController extends AdminController
  16. {
  17. /**
  18. * Make a grid builder.
  19. *
  20. * @return Grid
  21. */
  22. protected function grid()
  23. {
  24. return Grid::make(new Store(), function (Grid $grid) {
  25. $grid->model()->orderBy('id','desc');
  26. $grid->id->sortable();
  27. $grid->logo_url->image('',50);
  28. $grid->name;
  29. $grid->market_id->display(function ($marketId){
  30. $market = MarketModel::getMarketInfo($marketId,'name');
  31. return empty($market) ? '' : $market->name;
  32. });
  33. $grid->mm_user_id->display(function ($mmUserId){
  34. $mmUser = MminfoModel::getMmInfo($mmUserId,'name');
  35. return empty($mmUser) ? '' : $mmUser->name;
  36. });
  37. $grid->store_applet_img->image('',50);
  38. $grid->cash_code_img->image('',50);
  39. $grid->sort->sortable();
  40. $grid->is_rest->switch();
  41. $grid->is_open->switch();
  42. // 搜索
  43. $grid->filter(function (Grid\Filter $filter) {
  44. $filter->equal('id');
  45. });
  46. // 每页10条
  47. $grid->paginate(10);
  48. });
  49. }
  50. /**
  51. * Make a show builder.
  52. *
  53. * @param mixed $id
  54. *
  55. * @return Show
  56. */
  57. protected function detail($id)
  58. {
  59. return Show::make($id, new Store(), function (Show $show) {
  60. $show->row(function (Show\Row $show) {
  61. });
  62. $show->row(function (Show\Row $show) {
  63. });
  64. $show->id;
  65. $show->mm_user_id;
  66. $show->market_id;
  67. $show->name;
  68. $show->address;
  69. $show->tel;
  70. $show->announcement;
  71. $show->is_rest;
  72. $show->logo;
  73. $show->details;
  74. $show->coordinates;
  75. $show->business_license;
  76. $show->store_type_id;
  77. $show->is_open;
  78. $show->sort;
  79. $show->user_id;
  80. $show->environment;
  81. $show->expire_time;
  82. $show->zm_img;
  83. $show->fm_img;
  84. $show->link_name;
  85. $show->link_tel;
  86. $show->admin_id;
  87. $show->loudspeaker_imei;
  88. $show->time;
  89. $show->time2;
  90. $show->time3;
  91. $show->time4;
  92. $show->created_at;
  93. $show->updated_at;
  94. });
  95. }
  96. /**
  97. * Make a form builder.
  98. *
  99. * @return Form
  100. */
  101. protected function form()
  102. {
  103. return Form::make(new Store(), function (Form $form) {
  104. // 查询市场经理
  105. $mmList = MminfoModel::getMmInfoArray();
  106. // 查询市场
  107. $marketList = MarketModel::getMarket();
  108. // 查询一级分类
  109. $categoryList = CategoryModel::getCategoryArray([['parent_id','=',0]]);
  110. // 用户
  111. $userList = UserModel::getUserArray();
  112. $form->column(6, function (Form $form) use($mmList,$marketList,$categoryList){
  113. $form->hidden('id');
  114. $form->select('mm_user_id')->options($mmList);
  115. $form->select('market_id')->required()->options($marketList);
  116. $form->select('category_id')->options($categoryList);
  117. $form->text('name')->required()->maxLength(50);
  118. $form->image('logo')->required();
  119. $form->mobile('tel');
  120. $form->text('link_name')->required();
  121. $form->mobile('link_tel')->required();
  122. $form->number('sort');
  123. $form->switch('is_rest')
  124. ->customFormat(function ($v) {
  125. return $v == '休息' ? 1 : 0;
  126. })
  127. ->saving(function ($v) {
  128. return $v;
  129. });
  130. $form->switch('is_open')
  131. ->customFormat(function ($v) {
  132. return $v == '开启' ? 1 : 0;
  133. })
  134. ->saving(function ($v) {
  135. return $v;
  136. })->default(1);
  137. $form->text('address');
  138. });
  139. $form->column(6, function (Form $form) {
  140. $form->image('business_license')->required();
  141. $form->image('zm_img')->required();
  142. $form->image('fm_img')->required();
  143. $form->text('admin_id')->required();/*需要优化 一个用户只能绑定一家店铺*/
  144. $form->text('user_id')->required();/*需要优化 一个用户只能绑定一家店铺*/
  145. $form->timeRange('time1','time2','营业时间段一')->required();
  146. $form->timeRange('time3','time4','营业时间段二');
  147. });
  148. $form->column(12, function (Form $form) {
  149. $form->map('lat','lng','地址');
  150. $form->textarea('introduction')->required();
  151. $form->textarea('announcement');
  152. $form->multipleImage('environment');
  153. });
  154. // $form->text('coordinates')->width(4)
  155. // ->placeholder('输入 经纬度,如: 108.281552,22.83731')
  156. // ->help("通过网址 <a href='https://lbs.amap.com/console/show/picker' target='_blank'>https://lbs.amap.com/console/show/picker</a> 获取经纬度");
  157. $form->saved(function (Form $form){
  158. $id = $form->getKey();
  159. $store = StoreModel::find($id);
  160. // 添加商户钱包
  161. $userBalance = UserBalanceModel::where([
  162. ['user_type','=',5],
  163. ['source_id','=',$id]
  164. ])->first();
  165. if(empty($userBalance)){
  166. $userBalance = new UserBalanceModel();
  167. $userBalance->user_type = 5;
  168. $userBalance->source_id = $id;
  169. $userBalance->save();
  170. }
  171. if($form->isCreating() && !empty($id)){
  172. $qrCode = new StoreQRCode();
  173. // 生成小程序码 店铺
  174. $sRes = $qrCode->SetStoreWeChatCode($id);
  175. // 生产小程序码 收银
  176. $pRes = $qrCode->SetPayWeChatCode($id);
  177. // 保存图片
  178. $store->store_applet_img = $sRes['status'] ? $sRes['path'] : '';
  179. $store->cash_code_img = $pRes['status'] ? $pRes['path'] : '';
  180. $store->save();
  181. // 剪裁图片
  182. // $form->image('cash_code_img')->crop(270, 270, [5, 5]);
  183. }
  184. });
  185. $form->disableResetButton();
  186. $form->disableViewCheck();
  187. $form->disableEditingCheck();
  188. $form->disableCreatingCheck();
  189. });
  190. }
  191. }