Merge branch 'feature/purchase_record' into dev

This commit is contained in:
luofei 2023-07-14 14:56:59 +08:00
commit 845a94616b
3 changed files with 36 additions and 21 deletions

View File

@ -2564,32 +2564,45 @@ class StoreOrderRepository extends BaseRepository
/** /**
* 采购订单列表 * 采购订单列表
* @param $merId * @param $uid
* @param $keyword
* @param $page * @param $page
* @param $limit * @param $limit
* @return \think\Collection * @return array
* @throws DataNotFoundException * @throws DataNotFoundException
* @throws DbException * @throws DbException
* @throws ModelNotFoundException * @throws ModelNotFoundException
*/ */
public function purchaseOrder($merId, $keyword, $page, $limit) public function purchaseOrder($uid, $keyword, $page, $limit)
{ {
$orders = StoreOrder::where('mer_id', $merId) $orders = StoreOrder::where('uid', $uid)
->where('pay_type', StoreGroupOrder::PAY_TYPE_CREDIT_BUY) ->where('activity_type', 98)
->where('status', StoreOrder::STATUS_WAIT_COMMENT) ->whereIn('status', [StoreOrder::STATUS_WAIT_COMMENT, StoreOrder::STATUS_FINISH])
->where('is_del', 0)
->where('is_system_del', 0)
->when($keyword !== '', function ($query) use ($keyword) { ->when($keyword !== '', function ($query) use ($keyword) {
$query->where('order_sn|user_phone', 'like', "%$keyword%"); $query->where('order_sn|user_phone', 'like', "%$keyword%");
}) })
->page($page, $limit) ->page($page, $limit)
->order('order_id', 'desc')
->select(); ->select();
$return = [];
foreach ($orders as $order) { foreach ($orders as $order) {
$products = $order->orderProduct; $products = $order->orderProduct;
foreach ($products as &$product) { $currentOrder = $order->toArray();
$purchaseRecord = PurchaseRecord::where(['order_id' => $product['order_id'], 'order_product_id' => $product['product_id'], 'order_unique' => $product['product_sku']])->field('sales_volume')->find(); foreach ($products as $k => $product) {
$product['sales_volume'] = empty($purchaseRecord) ? 0 : $purchaseRecord->sales_volume; $purchaseRecord = PurchaseRecord::where(['order_id' => $product['order_id'], 'order_product_id' => $product['product_id'], 'order_unique' => $product['product_sku']])->field('mer_id,product_id,unique,number,sales_volume')->find();
if (!empty($purchaseRecord)) {
$currentOrder['orderProduct'][$k]['sales_volume'] = $purchaseRecord->sales_volume;
$currentOrder['orderProduct'][$k]['purchase_record'] = $purchaseRecord->toArray();
} else {
$currentOrder['orderProduct'][$k]['sales_volume'] = 0;
$currentOrder['orderProduct'][$k]['purchase_record'] = [];
}
} }
$return[] = $currentOrder;
} }
return $orders; return $return;
} }
} }

View File

@ -2286,12 +2286,12 @@ class ProductRepository extends BaseRepository
if (!$unique) { if (!$unique) {
throw new \Exception('商品规格导入出错', 500); throw new \Exception('商品规格导入出错', 500);
} }
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('unique', $unique)->find();
} else { } else {
$productId = $this->import($params['order_product_id'], request()->userInfo(), $params['order_unique']); $productId = $this->import($params['order_product_id'], request()->userInfo());
$product = $this->get($productId); $product = $this->get($productId);
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $productId)->find();
} }
$sku = ProductAttrValue::where('product_id', $params['order_product_id'])->where('unique', $params['order_unique'])->value('sku');
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('sku', $sku)->find();
} else { } else {
//有商品有规格 //有商品有规格
$product = $this->get($params['product_id']); $product = $this->get($params['product_id']);
@ -2355,7 +2355,7 @@ class ProductRepository extends BaseRepository
* @return bool * @return bool
* @throws \Exception * @throws \Exception
*/ */
public function import($product_id, $user, $unique = null) public function import($product_id, $user)
{ {
$mer_id = Db::name('store_service')->where('uid', $user['uid'])->where('status', 1)->value('mer_id'); $mer_id = Db::name('store_service')->where('uid', $user['uid'])->where('status', 1)->value('mer_id');
if ($mer_id == 0) { if ($mer_id == 0) {
@ -2374,8 +2374,7 @@ class ProductRepository extends BaseRepository
foreach ($attr as $item) { foreach ($attr as $item) {
$find['attr'][] = ['attr_name' => $item['attr_name'], 'detail' => explode('-!-', $item['attr_values'])]; $find['attr'][] = ['attr_name' => $item['attr_name'], 'detail' => explode('-!-', $item['attr_values'])];
} }
$where = empty($unique) ? ['product_id' => $find['product_id']] : ['product_id' => $find['product_id'], 'unique' => $unique]; $find['attrValue'] = Db::name('store_product_attr_value')->where(['product_id' => $find['product_id']])->field('image,price,cost,ot_price,svip_price,0 as stock,bar_code,weight,volume,detail')->select()->each(function ($item) {
$find['attrValue'] = Db::name('store_product_attr_value')->where($where)->field('image,price,cost,ot_price,svip_price,0 as stock,bar_code,weight,volume,detail')->select()->each(function ($item) {
$item['detail'] = empty($item['detail']) ? [] : json_decode($item['detail'], true); $item['detail'] = empty($item['detail']) ? [] : json_decode($item['detail'], true);
return $item; return $item;
})->toArray(); })->toArray();
@ -2407,16 +2406,19 @@ class ProductRepository extends BaseRepository
* @param $oldProductId * @param $oldProductId
* @param $product * @param $product
* @param $unique * @param $unique
* @return false * @return bool
*/ */
public function importAttrValue($oldProductId, $product, $unique) public function importAttrValue($oldProductId, $product, $unique)
{ {
$product['attrValue'] = ProductAttrValue::where(['product_id' => $oldProductId, 'unique' => $unique])->field('image,price,cost,ot_price,svip_price,0 as stock,bar_code,weight,volume,detail')->select(); $product['attrValue'] = ProductAttrValue::where(['product_id' => $oldProductId])->field('image,price,cost,ot_price,svip_price,0 as stock,bar_code,weight,volume,detail')->select();
$settleParams = $this->setAttrValue($product, $product['product_id'], 0, 0, $product['mer_id']); $settleParams = $this->setAttrValue($product, $product['product_id'], 0, 0, $product['mer_id']);
if (!empty($settleParams['attrValue'])) { if (!empty($settleParams['attrValue'])) {
if (ProductAttrValue::getInstance()->insert($settleParams['attrValue'][0]) !== false) { foreach ($settleParams['attrValue'] as $item) {
return $settleParams['attrValue'][0]['unique']; if (!ProductAttrValue::getInstance()->insert($item)) {
throw new ValidateException('商品规格保存出错');
}
} }
return true;
} }
return false; return false;
} }

View File

@ -388,7 +388,7 @@ class StoreOrder extends BaseController
{ {
[$page, $limit] = $this->getPage(); [$page, $limit] = $this->getPage();
$keyword = $this->request->param('keyword'); $keyword = $this->request->param('keyword');
$list = $orderRepository->purchaseOrder($merId, $keyword, $page, $limit); $list = $orderRepository->purchaseOrder($this->request->uid(), $keyword, $page, $limit);
return app('json')->success($list); return app('json')->success($list);
} }