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

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