123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace app\admin\controller\order;
- use app\admin\validate\coupon\CouponValidate;
- use app\admin\validate\device\DeviceValidate;
- use app\admin\validate\order\OrderValidate;
- use app\controller\Curd;
- use app\model\Coupon;
- use app\model\Device;
- use app\model\Order;
- use app\model\OrderSheet;
- use app\model\Supplier;
- use app\model\SysSerial;
- use support\exception\BusinessException;
- use support\Request;
- use support\Response;
- class CompleteController extends Curd
- {
- public function __construct()
- {
- $this->model = new Order();
- $this->validate = true;
- $this->validateClass = new OrderValidate();
- }
- /**
- * @Desc 列表
- * @Author Gorden
- * @Date 2024/3/28 15:01
- *
- * @param Request $request
- * @return Response
- * @throws \support\exception\BusinessException
- */
- public function select(Request $request): Response
- {
- [$where, $format, $limit, $field, $order] = $this->selectInput($request);
- $order = $request->get('order', 'desc');
- $field = $field ?? 'order_addtimes';
- $where['order_status_system'] = 'CONFIRM';
- $where['order_is_complete'] = ['in', ['Y', 'R']];
- $query = $this->doSelect($where, $field, $order);
- return $this->doFormat($query, $format, $limit);
- }
- /**
- * @Desc 订单商品详情
- * @Author Gorden
- * @Date 2024/3/29 8:50
- *
- * @param Request $request
- * @return Response
- */
- public function sheet(Request $request)
- {
- $orderId = $request->get('order_id');
- $orderSheet = OrderSheet::with([
- 'member' => function ($query) {
- $query->select('member_id', 'member_mobile');
- },
- 'goods' => function ($query) {
- $query->select('goods_id', 'goods_name', 'goods_cover', 'goods_market_price', 'goods_sales_price', 'join_goods_supplier_id');
- },
- 'memberInfo',
- 'cert'
- ])->where('join_sheet_order_id', $orderId)
- ->get()
- ->toArray();
- foreach ($orderSheet as &$item) {
- $item['goods']['goods_cover'] = getenv('STORAGE_DOMAIN') . $item['goods']['goods_cover'];
- $item['goods']['supplier_name'] = '';
- if (!empty($item['goods']['join_goods_supplier_id'])) {
- $supplier = Supplier::where('supplier_id',$item['goods']['join_goods_supplier_id'])->value('supplier_name');
- if ($supplier){
- $item['goods']['supplier_name'] = $supplier;
- }
- }
- }
- $order = Order::where('order_id', $orderId)->first();
- $data = [
- 'order' => $order,
- 'sheet' => $orderSheet
- ];
- return json_success('', $data);
- }
- protected function updateInput(Request $request): array
- {
- $primary_key = $this->model->getKeyName();
- $id = $request->post($primary_key);
- $data = $this->inputFilter($request->post());
- $data['coupon_begindate'] = strtotime($data['coupon_begindate']);
- $data['coupon_enddate'] = strtotime($data['coupon_enddate']);
- $model = $this->model->find($id);
- if (!$model) {
- throw new BusinessException('记录不存在', 2);
- }
- unset($data[$primary_key]);
- return [$id, $data];
- }
- }
|