From 5de2d0d40815bfb0157fc0f3663f5d70663de1a4 Mon Sep 17 00:00:00 2001 From: lqmac Date: Fri, 8 Mar 2024 13:14:23 +0800 Subject: [PATCH] 1 --- app/admin/controller/Goods.php | 2 +- app/admin/controller/Store.php | 2 +- app/admin/model/Store.php | 73 +++++++++++++++++++++++++++++++++- app/api/controller/User.php | 10 ++++- app/api/service/Goods.php | 2 +- app/common/model/Goods.php | 45 +++++++++++++++++++++ 6 files changed, 129 insertions(+), 5 deletions(-) diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index d6d9e43e..f21ed00d 100644 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -35,7 +35,7 @@ class Goods extends Controller $model = new GoodsModel; $params = $this->request->param(); $params['store_id'] = 0; - $list= $model->getList($params); + $list= $model->getAdminList($params); return $this->renderSuccess(compact('list')); } diff --git a/app/admin/controller/Store.php b/app/admin/controller/Store.php index 4c8bc1c9..5288dc95 100644 --- a/app/admin/controller/Store.php +++ b/app/admin/controller/Store.php @@ -227,7 +227,7 @@ class Store extends Controller - + diff --git a/app/admin/model/Store.php b/app/admin/model/Store.php index 954dcaad..5d89719e 100644 --- a/app/admin/model/Store.php +++ b/app/admin/model/Store.php @@ -17,7 +17,9 @@ use app\admin\model\store\User as StoreUserModel; use app\admin\model\user\User; use app\common\model\Store as StoreModel; use app\common\model\User as UserModel; - +use think\facade\Db; +use app\store\model\Category as CategoryModel; +use app\common\model\UploadFile; /** * 商家记录表模型 * Class Store @@ -67,11 +69,80 @@ class Store extends StoreModel if ($user_id) { (new StoreUserModel)->where(['store_id' => $this['store_id']])->save(['user_id' => $user_id]); } + $this->copyCategory((int)$this['store_id']); } return $status; }); } + public function copyCategory(int $new_store_id){ + $store_id = 0; + $model = new CategoryModel; + $list = $model->getList(['store_id' =>$store_id]); + if (!$list) { + return; + } + foreach ($list as $value) { + $value = $value->toArray(); + $value['store_id'] = $new_store_id; + $value['create_time'] = time(); + $value['update_time'] = time(); + $value['image_id'] = $value['image_id'] ? $this->copyImage($value['image_id'], $new_store_id) : 0; + $temp = $value; + unset($temp['children']); + unset($temp['image']); + unset($temp['category_id']); + + $firstid = Db::table('yoshop_category')->insertGetId($temp); + + + if (!isset($value['children']) || !$value['children']) { + continue; + } + foreach ($value['children'] as $value1) { + $value1 = $value1->toArray(); + $value1['parent_id'] = $firstid; + $value1['store_id'] = $new_store_id; + $value1['create_time'] = time(); + $value1['update_time'] = time(); + $value1['image_id'] = $value1['image_id'] ? $this->copyImage($value1['image_id'], $new_store_id) : 0; + $temp1 = $value1; + unset($temp1['children']); + unset($temp1['image']); + unset($temp1['category_id']); + + $secondid = Db::table('yoshop_category')->insertGetId($temp1); + if (!isset($value1['children']) || !$value1['children']) { + continue; + } + foreach ($value1['children'] as $value2) { + $value2 = $value2->toArray(); + $value2['parent_id'] = $secondid; + $value2['store_id'] = $new_store_id; + $value2['create_time'] = time(); + $value2['update_time'] = time(); + $value2['image_id'] = $value2['image_id'] ? $this->copyImage($value2['image_id'], $new_store_id) : 0; + $temp2 = $value2; + unset($temp2['children']); + unset($temp2['image']); + unset($temp2['category_id']); + Db::table('yoshop_category')->insertGetId($temp2); + } + } + } + } + + public function copyImage($image_id, $store_id){ + $upload_file = DB::table("yoshop_upload_file")->where('file_id', $image_id)->find(); + if (!$upload_file) { + return 0; + } + $upload_file['store_id'] = $store_id; + $upload_file['create_time'] = time(); + unset($upload_file['file_id']); + $new_image_id = DB::table("yoshop_upload_file")->insertGetId($upload_file); + return $new_image_id; + } /** * 移入移出回收站 * @param bool $isRecycle diff --git a/app/api/controller/User.php b/app/api/controller/User.php index a7df8240..4dc06861 100644 --- a/app/api/controller/User.php +++ b/app/api/controller/User.php @@ -30,7 +30,8 @@ use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; use think\response\Json; - +use app\common\model\dealer\Order as DealerOrderModel; +use app\common\model\Order as OrderModel; /** * 用户管理 * Class User @@ -338,6 +339,13 @@ class User extends Controller $log = InviteLog::where('invitee_user_id', $value['user_id'])->find(); $user = UserModel::where('user_id', $log['user_id'] ?? 0)->field('user_id,nick_name,mobile')->find(); $value['inviter'] = $user; + $value['order_num'] = 0; + if ($value['user_type'] == 10 || $value['user_type'] == 20) { + $value['order_num'] = OrderModel::where('user_id', $value['user_id'])->count(); + } elseif ($value['user_type'] == 30) { + $value['order_num'] = DealerOrderModel::where('first_user_id|second_user_id|third_user_id', '=', $value['user_id'])->count(); + } + } return $this->renderSuccess(compact('list')); diff --git a/app/api/service/Goods.php b/app/api/service/Goods.php index 8b5958cb..923456d2 100644 --- a/app/api/service/Goods.php +++ b/app/api/service/Goods.php @@ -352,7 +352,7 @@ class Goods extends GoodsService $temp['goods_price_min'] = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); } elseif (UserService::isDealerMember()) { $priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); - $temp['goods_price_min'] = $priceArr['goods_price_min_dealer']; + $temp['goods_price_min'] = $priceArr['distributionPrice']; } } $data[] = $temp; diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 2b686207..4664e8c7 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -167,7 +167,49 @@ class Goods extends BaseModel { return $this->hasMany('Comment'); } + /** + * 获取商品列表 + * @param array $param 查询条件 + * @param int $listRows 分页数量 + * @return mixed + * @throws DbException + */ + public function getAdminList(array $param = [], int $listRows = 15) + { + // 筛选条件 + $query = $this->getQueryFilter($param); + // 设置显示的销量 goods_sales + $query->field(['(sales_initial + sales_actual) as goods_sales', '(line_price_max - goods_price_min) as discount']); + // 排序条件 + $sort = $this->setQuerySort($param); + $order = request()->get()['order'] ?? ''; + $sort = request()->get()['sort'] ?? ''; + if ($order && $sort) { + $sort = [ + $sort=> $order, + ]; + } else { + $sort = [ + $this->getPk() => 'desc', + ]; + } + + + + $field = $this->getAliasFields($this->name, ['content']); + $field[] = 'selling_point'; + // 执行查询 + $list = $query->with(['images.file']) + ->alias($this->name) + ->field($field) + ->where('is_delete', '=', 0) + ->order($sort) + ->paginate($listRows); + + // 整理列表数据并返回 + return $this->setGoodsListData($list); + } /** * 获取商品列表 * @param array $param 查询条件 @@ -328,6 +370,9 @@ class Goods extends BaseModel if (isset($param['store_id']) && $param['store_id'] !== '') { $filter[] = ['goods.store_id', '=', $params['store_id']]; } + if (isset($param['channel']) && $param['channel'] !== '') { + $filter[] = ['goods.channel', '=', $params['channel']]; + } // 实例化新查询对象 return $query->where($filter); }