Merge pull request 'dev' (#55) from dev into preview

Reviewed-on: #55
This commit is contained in:
mkm 2023-10-28 16:10:24 +08:00
commit 273958d35b
104 changed files with 146 additions and 126 deletions

View File

@ -192,11 +192,11 @@ class UserBillDao extends BaseDao
return UserBill::getDB()
->when(isset($where['now_money']) && in_array($where['now_money'], [0, 1, 2]), function ($query) use ($where) {
if ($where['now_money'] == 0)
$query->where('category', 'now_money')->whereIn('type', ['pay_product', 'recharge', 'sys_inc_money', 'sys_dec_money', 'brokerage', 'presell', 'refund']);
$query->where('category', 'now_money')->whereIn('type', ['pay_product', 'recharge', 'sys_inc_money', 'sys_dec_money', 'brokerage', 'presell', 'refund', 'zhibo_reward_inc', 'zhibo_reward_dec']);
else if ($where['now_money'] == 1)
$query->where('category', 'now_money')->whereIn('type', ['pay_product', 'sys_dec_money', 'presell']);
$query->where('category', 'now_money')->whereIn('type', ['pay_product', 'sys_dec_money', 'presell', 'zhibo_reward_dec']);
else if ($where['now_money'] == 2)
$query->where('category', 'now_money')->whereIn('type', ['recharge', 'sys_inc_money', 'brokerage', 'refund']);
$query->where('category', 'now_money')->whereIn('type', ['recharge', 'sys_inc_money', 'brokerage', 'refund', 'zhibo_reward_inc']);
})
->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
$query->where('uid', $where['uid'])->where('mer_id', 0);

View File

@ -682,35 +682,39 @@ class CommunityRepository extends BaseRepository
$entrustInfo->update($value);
continue;
}
$purchaseRecord = PurchaseRecord::where('unique', $value['product_attr_unique'])->find();
$totalNumber = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('number');
$totalSalesVolume = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('sales_volume');
if (empty($purchaseRecord) || ($totalNumber - $totalSalesVolume) <= 0) {
throw new ValidateException('进货记录不存在或已售罄');
}
if (($totalNumber - $totalSalesVolume) < $value['number']) {
throw new ValidateException('库存不足');
}
// $purchaseRecord = PurchaseRecord::where('unique', $value['product_attr_unique'])->find();
// $totalNumber = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('number');
// $totalSalesVolume = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('sales_volume');
// if (empty($purchaseRecord) || ($totalNumber - $totalSalesVolume) <= 0) {
// throw new ValidateException('进货记录不存在或已售罄');
// }
// if (($totalNumber - $totalSalesVolume) < $value['number']) {
// throw new ValidateException('库存不足');
// }
if ($value) {
$insert[] = [
'community_id' => $id,
'purchase_record_id' => $purchaseRecord['id'],
'product_id' => $purchaseRecord['product_id'],
'product_attr_unique' => $purchaseRecord['unique'],
'mer_id' => $purchaseRecord['mer_id'],
'entrust_mer_id' => $entrustMerId,
'entrust_day' => $entrustDay,
'number' => $value['number'],
'price' => $value['price'],
'update_time' => date('Y-m-d H:i:s'),
];
$attrValue = ProductAttrValue::where('unique', $value['product_attr_unique'])->find();
if($attrValue){
$insert[] = [
'community_id' => $id,
'purchase_record_id' => 0,//$purchaseRecord['id'],
'product_id' => $attrValue['product_id'],
'product_attr_unique' => $attrValue['unique'],
'mer_id' => $attrValue['mer_id'],
'entrust_mer_id' => $entrustMerId,
'entrust_day' => $entrustDay,
'number' => $value['number'],
'price' => $value['price'],
'update_time' => date('Y-m-d H:i:s'),
];
$attrValue->stock -= $value['number'];
$attrValue->save();
}
}
$purchaseRecord->product->stock -= $value['number'];
$purchaseRecord->product->save();
$attrValue = ProductAttrValue::where('product_id', $purchaseRecord['product_id'])->where('unique', $purchaseRecord['unique'])->find();
$attrValue->stock -= $value['number'];
$attrValue->save();
// $purchaseRecord->product->stock -= $value['number'];
// $purchaseRecord->product->save();
}
if ($insert) {
Entrust::getInstance()->insertAll($insert);

View File

@ -2325,23 +2325,65 @@ class ProductRepository extends BaseRepository
*/
public function stockIn($merId, $params)
{
/**感觉有问题 最好在优化一下结构 */
Db::startTrans();
try {
$supplierMerId = 0;
$model = new PurchaseRecord();
if (empty($params['product_id']) && !empty($params['order_product_id'])) {
//有商品无规格或者无商品无规格,导入商品和规格
$product = $this->getWhere(['source_product_id' => $params['order_product_id'], 'mer_id' => $merId]);
$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();
if (!empty($product)) {
$unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']);
if (!$unique) {
throw new \Exception('商品规格导入出错', 500);
$stockIn = $params['number'] ?? 0;
$price = $params['price'] ?? 0;
if (!empty($params['order_id'])) {
//采购、委托订单导入
$orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id');
$orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])->where('product_sku', $params['order_unique'])->find();
if (empty($orderProduct)) {
$unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']);
if (!$unique) {
throw new \Exception('商品规格导入出错', 500);
}
}
if( $orderProduct->is_imported == 1){
if($stockIn==0){
$stockIn=1;
}
ProductAttrValue::where('mer_id', $merId)
->where('product_id', $product['product_id'])
->update(['stock'=>$attrValue->stock + $stockIn]);
$data = [
'order_id' => $params['order_id'] ?? 0,
'order_product_id' => $params['order_product_id'] ?? 0,
'product_id' => $product->product_id,
'number' => $stockIn,
'order_unique' => $params['order_unique'] ?? '',
'unique' => $attrValue['unique'],
'price' => $price,
'mer_id' => $product->mer_id,
'supplier_mer_id' => $orderMerId??0,
];
if (!$model->save($data)) {
throw new \Exception('入库失败', 500);
}
Db::commit();
return true;
}
$stockIn = $orderProduct['product_num'] ?? 0;
$price = $orderProduct['product_price'] ?? 0;
$supplierMerId = $orderMerId ?? 0;
// 如果是委托商品入库后就成为供应链商家的采购类型商品
if ($orderProduct['product_type'] == 99) {
$product->product_type = 98;
}
}
} else {
$productId = $this->import($params['order_product_id'], request()->userInfo());
$product = $this->get($productId);
}
$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 {
//有商品有规格
$product = $this->get($params['product_id']);
@ -2350,23 +2392,6 @@ class ProductRepository extends BaseRepository
if (!$product || !$attrValue) {
throw new DataNotFoundException('商品或规格不存在');
}
$stockIn = $params['number'] ?? 0;
$price = $params['price'] ?? 0;
if (!empty($params['order_id'])) {
//采购、委托订单导入
$orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id');
$orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])->where('product_sku', $params['order_unique'])->find();
if (empty($orderProduct) || $orderProduct->is_imported == 1) {
throw new ValidateException('订单商品不存在或已入库');
}
$stockIn = $orderProduct['product_num'] ?? 0;
$price = $orderProduct['product_price'] ?? 0;
$supplierMerId = $orderMerId ?? 0;
// 如果是委托商品入库后就成为供应链商家的采购类型商品
if ($orderProduct['product_type'] == 99) {
$product->product_type = 98;
}
}
if ($stockIn <= 0) {
throw new ValidateException('入库数量不能小于等于0');
}
@ -2376,7 +2401,6 @@ class ProductRepository extends BaseRepository
if (!$product->save()) {
throw new \Exception('商品库存保存失败', 500);
}
$model = new PurchaseRecord();
$data = [
'order_id' => $params['order_id'] ?? 0,
'order_product_id' => $params['order_product_id'] ?? 0,

View File

@ -195,7 +195,7 @@ class MerchantIntention extends BaseController
'city' => $areaInfo['city_code'] ?? '',
'area' => $merInfo['area_id'] ?? '',
'street' => $merInfo['street_id'] ?? '',
'address' => $merInfo['address'] ?? '',
'address' => $intenInfo['address'] ?? '',
'bank_username' => $data['bank_username'] ?? '',
'bank_opening' => $data['bank_opening'] ?? '',
'bank_front' => $data['bank_front'] ?? '',

View File

@ -64,7 +64,7 @@ class Zhibo extends BaseController
$user->save();
$userBillRepository = app()->make(UserBillRepository::class);
//打赏人账单
$userBillRepository->decBill($user['uid'], 'now_money', 'zhibo_reward', [
$userBillRepository->decBill($user['uid'], 'now_money', 'zhibo_reward_dec', [
'link_id' => $orderId,
'status' => 1,
'title' => '直播送礼支出',
@ -76,7 +76,7 @@ class Zhibo extends BaseController
Db::name('user')->where('uid', $params['master_id'])->inc('now_money', $params['amount'])->update();
$master = Db::name('user')->where('uid', $params['master_id'])->find();
//主播账单
$userBillRepository->incBill($master['uid'], 'now_money', 'zhibo_reward', [
$userBillRepository->incBill($master['uid'], 'now_money', 'zhibo_reward_inc', [
'link_id' => $orderId,
'status' => 1,
'title' => '直播送礼收入',

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More