WxUsedOrderGoodsController.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace App\Admin\Controllers\Used;
  3. use App\Admin\Actions\Grid\OrderGoodsAction;
  4. use App\Admin\Repositories\Shop\WxShopOrderGoods;
  5. use App\Models\Shop\WxShopOrderGoods as OrderGoodsModel;
  6. use App\Models\Shop\WxShopOrder;
  7. use App\Wen\Utils\Settings;
  8. use Dcat\Admin\Form;
  9. use Dcat\Admin\Grid;
  10. use Dcat\Admin\Show;
  11. use Dcat\Admin\Http\Controllers\AdminController;
  12. class WxUsedOrderGoodsController extends AdminController
  13. {
  14. /**
  15. * Make a grid builder.
  16. *
  17. * @return Grid
  18. */
  19. protected function grid()
  20. {
  21. $app_coin_name = Settings::get('app_coin_name', '硬币');
  22. OrderGoodsModel::whereNull('buyer_user_id')->where('goods_type', 6)->orderBy('id', 'desc')->limit(20)->get()->map(function ($v){
  23. $user_id = WxShopOrder::withTrashed()->where('id', $v->order_id)->value('user_id');
  24. if($user_id !== null){
  25. OrderGoodsModel::where('id', $v->id)->update([
  26. 'buyer_user_id' => $user_id
  27. ]);
  28. }
  29. });
  30. return Grid::make(new WxShopOrderGoods(), function (Grid $grid) use ($app_coin_name){
  31. $grid->simplePaginate();
  32. $grid->quickSearch(['id', 'name'])->placeholder('搜索订单商品ID,名字...');
  33. $grid->model()->whereIn('goods_type', [6])->orderBy('id', 'desc');
  34. $grid->column('id')->sortable();
  35. // $grid->column('order_id', '站内订单id')->display(function ($v){
  36. // return '<a href="'.admin_url('/shop/order?id='.$v).'" target="_blank">订单'.$v.'</a>';
  37. // });
  38. $grid->column('seller', '卖家')->display(function ($v) {
  39. $user = $this->seller;
  40. if($user){
  41. return '<div style="display: flex;"><img src="' . ($user['user_avatar'] ?? Settings::get('img_default', 'https://img.mini.minisns.cn/icons/dafault.png')) . '" style="border-radius:50px;width:30px;" />'.('<div style="display: flex;flex-direction: column;justify-content: center;margin-left: 4px;"><a target="_blank" href="'.admin_url('users?id='.$user['id']).'">'.$user['user_name'].'</a></div>' ?? '').'</div>';
  42. }
  43. return '';
  44. })->width('50px');
  45. $grid->column('buyers', '买家')->display(function ($v) {
  46. $user = $this->buyer;
  47. if($user){
  48. return '<div style="display: flex;"><img src="' . ($user['user_avatar'] ?? Settings::get('img_default', 'https://img.mini.minisns.cn/icons/dafault.png')) . '" style="border-radius:50px;width:30px;" />'.('<div style="display: flex;flex-direction: column;justify-content: center;margin-left: 4px;"><a target="_blank" href="'.admin_url('users?id='.$user['id']).'">'.$user['user_name'].'</a></div>' ?? '').'</div>';
  49. }
  50. return '';
  51. })->width('50px');
  52. $grid->column('pic')->image('', 80);
  53. $grid->column('name');
  54. $grid->column('product')->limit(20);
  55. $grid->column('vip_price')->display(function ($v) use ($app_coin_name){
  56. if($this->credit_type == 1){
  57. return '¥'.$v;
  58. }else{
  59. return $v.$app_coin_name;
  60. }
  61. })->sortable();
  62. $grid->column('price')->display(function ($v) use ($app_coin_name){
  63. if($this->credit_type == 1){
  64. return '¥'.$v;
  65. }else{
  66. return $v.$app_coin_name;
  67. }
  68. })->sortable();
  69. $grid->column('recharge')->display(function ($v) use ($app_coin_name){
  70. if($this->credit_type == 1){
  71. return '¥'.$v;
  72. }else{
  73. return $v.$app_coin_name;
  74. }
  75. })->sortable();
  76. $grid->column('quantity');
  77. $grid->column('goods_id');
  78. $grid->column('product_id');
  79. // $grid->column('type')->using([0 => '正常购买', 1 => '补发', 2 => '赠送'])->label([
  80. // 0 => 'green',
  81. // 1 => 'blue',
  82. // 2 => 'orange2'
  83. // ]);
  84. $grid->column('state')->using([0 => '无售后申请', 1 => '② 买家申请退款(待退款)', 2 => '① 卖家协商退货中(协商退货)', 3 => '③ 已退款(售后完结)', 4 => '异常'])->label([
  85. 0 => 'silver',
  86. 1 => 'red',
  87. 2 => 'red',
  88. 3 => 'green',
  89. 5 => 'primary',
  90. ]);
  91. $grid->column('created_at');
  92. // $grid->column('updated_at')->sortable();
  93. $grid->filter(function (Grid\Filter $filter) {
  94. $filter->equal('id');
  95. $filter->equal('order_id');
  96. });
  97. $grid->actions(function (Grid\Displayers\Actions $actions) {
  98. $actions->append((new OrderGoodsAction(6))->setKey($this->id));
  99. });
  100. $grid->disableCreateButton();
  101. // $grid->disableActions();
  102. $grid->disableViewButton();
  103. // 禁用编辑按钮
  104. $grid->disableEditButton();
  105. $grid->disableDeleteButton();
  106. });
  107. }
  108. /**
  109. * Make a show builder.
  110. *
  111. * @param mixed $id
  112. *
  113. * @return Show
  114. */
  115. protected function detail($id)
  116. {
  117. return Show::make($id, new WxShopOrderGoods(), function (Show $show) {
  118. $show->field('id');
  119. $show->field('pic');
  120. $show->field('name');
  121. $show->field('product');
  122. $show->field('vip_price');
  123. $show->field('price');
  124. $show->field('recharge');
  125. $show->field('quantity');
  126. $show->field('order_id');
  127. $show->field('goods_id');
  128. $show->field('product_id');
  129. $show->field('type');
  130. $show->field('state');
  131. $show->field('created_at');
  132. $show->field('updated_at');
  133. $show->disableEditButton();
  134. });
  135. }
  136. /**
  137. * Make a form builder.
  138. *
  139. * @return Form
  140. */
  141. protected function form()
  142. {
  143. return Form::make(new WxShopOrderGoods(), function (Form $form) {
  144. $form->display('id');
  145. $form->text('pic');
  146. $form->text('name');
  147. $form->text('product');
  148. $form->text('vip_price');
  149. $form->text('price');
  150. $form->text('recharge');
  151. $form->text('quantity');
  152. $form->text('order_id');
  153. $form->text('goods_id');
  154. $form->text('product_id');
  155. $form->text('type');
  156. $form->text('state');
  157. $form->deleting(function (Form $form){
  158. global $__MINI_GLOBAL_TENANT_ID__;
  159. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  160. return $form->response()->error('权限不足,不可以删除其他分站对象');
  161. }
  162. });
  163. });
  164. }
  165. }