validate()) return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; if (empty($this->user_id)) { return [ 'code' => 1, 'msg' => '请先选择用户', ]; } $order = Order::find() ->where([ 'user_id' => $this->user_id, 'store_id' => $this->store_id, 'order_origin' => Order::ORDER_SOURCE_CASHIER, 'is_pay' => 1 ]) ->orderBy('id desc')->one(); if (!$order) { return [ 'code' => 1, 'msg' => '没有可复用商品订单', ]; } $goods_id = explode(',', $this->goods_id); $orderDetail = OrderDetail::find()->where(['order_id' => $order->id, 'goods_id' => $goods_id])->all(); $rs = []; foreach ($orderDetail as $d) { $rs[] = [ 'goods_id' => $d['goods_id'], 'price' => bcdiv($d['total_price'], $d['num'], 2), ]; } return [ 'code' => 0, 'data' => $rs ]; } }