|
@@ -3,12 +3,15 @@
|
|
|
namespace App\Modules\Mini\Services;
|
|
|
|
|
|
use App\Base\BaseService;
|
|
|
+use App\Base\Utils;
|
|
|
use App\Events\OrderCreateEvent;
|
|
|
use App\Models\Cart;
|
|
|
use App\Models\Goods\Goods;
|
|
|
+use App\Models\Goods\GoodsCustom;
|
|
|
use App\Models\Order\Order;
|
|
|
use App\Models\Order\OrderGoods;
|
|
|
use App\Models\User\User;
|
|
|
+use Illuminate\Database\Eloquent\Builder;
|
|
|
use Illuminate\Support\Arr;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
@@ -79,4 +82,47 @@ class OrderService extends BaseService
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ public function paginate($uid, $params)
|
|
|
+ {
|
|
|
+ $p = Order::where("user_id", $uid)->orderByDesc("id")->paginate($params['page_size']);
|
|
|
+
|
|
|
+ return [
|
|
|
+ "total" => $p->total(),
|
|
|
+ "page_total" => $p->lastPage(),
|
|
|
+ "list" => array_map(function (Order $model) {
|
|
|
+ /** @var OrderGoods $firstGoods */
|
|
|
+ $firstGoods = $model->goods->first();
|
|
|
+ return [
|
|
|
+ "id" => $model->id,
|
|
|
+ "no" => $model->goods->pluck("sn")->implode("\sn"),
|
|
|
+ "goods_name" => $firstGoods->goods->name,
|
|
|
+ "goods_sn" => $firstGoods->sn,
|
|
|
+ "user_id" => Utils::idNo4($model->user_id),
|
|
|
+ "thumb" => $firstGoods->goods->thumb,
|
|
|
+ "email" => $model->user->email,
|
|
|
+ "created_at" => $model->created_at->format("Y-m-d H:i:s"),
|
|
|
+ "goods" => $model->goods->map(function (OrderGoods $goods) {
|
|
|
+ return [
|
|
|
+ "goods_id" => $goods->id,
|
|
|
+ "goods_name" => $goods->goods->name,
|
|
|
+ "goods_thumb" => $goods->goods->thumb,
|
|
|
+ "goods_sn" => $goods->sn,
|
|
|
+ "goods_count" => $goods->count,
|
|
|
+ "custom" => array_map(function ($custom) {
|
|
|
+ return [
|
|
|
+ "custom_id" => $custom['custom_id'],
|
|
|
+ "title" => GoodsCustom::where("id", $custom['custom_id'])->value("title"),
|
|
|
+ "value" => $custom['value'] ?? "",
|
|
|
+ ];
|
|
|
+ }, $goods->custom ?? []),
|
|
|
+ ];
|
|
|
+ }),
|
|
|
+ "phone" => $model->user->phone,
|
|
|
+ "name" => $model->user->name,
|
|
|
+ "source" => $model->source,
|
|
|
+ ];
|
|
|
+ }, $p->items()),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
}
|