Merge pull request 'dev' (#250) from dev into main

Reviewed-on: #250
This commit is contained in:
mkm 2024-10-10 16:20:13 +08:00
commit 78011ff850
6 changed files with 81 additions and 4 deletions

View File

@ -59,6 +59,14 @@ class BeforehandOrderController extends BaseAdminController
$result = BeforehandOrderLogic::add($params);
return $this->success('添加成功', [], 1, 1);
}
/**
* 生成支付订单
*/
public function generateOrder(){
$params = $this->request->post();
$result = BeforehandOrderLogic::generateOrder($params);
return $this->success('生成成功', [], 1, 1);
}
/**
* 一键出库
*/

View File

@ -43,7 +43,7 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
public function lists(): array
{
return BeforehandOrder::where($this->searchWhere)
->field(['id','order_id', 'uid','total_num','total_price','admin_id', 'pay_price', 'deduction_price','create_time', 'status', 'mark'])
->field(['id','order_id', 'uid','order_type','total_num','total_price','admin_id', 'pay_price', 'deduction_price','create_time', 'status', 'mark'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item){
@ -52,6 +52,13 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
}else{
$item->admin_name='';
}
if($item->order_type==1){
$item->order_type_name='普通订单';
}elseif($item->order_type==2){
$item->order_type_name='商贩订单';
}elseif($item->order_type==3){
$item->order_type_name='一条龙订单';
}
})
->toArray();
}

View File

@ -4,12 +4,16 @@ namespace app\admin\logic\beforehand_order;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\api\logic\order\CartLogic;
use app\api\logic\order\OrderLogic;
use app\common\model\beforehand_order\BeforehandOrder;
use app\common\logic\BaseLogic;
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
use app\common\model\user\User;
use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product\WarehouseProduct;
use support\exception\BusinessException;
@ -77,6 +81,53 @@ class BeforehandOrderLogic extends BaseLogic
}
}
/**
* @notes 生成支付订单
* @param array $params
* @return bool
* @author admin
* @date 2024/09/30 11:26
*/
public static function generateOrder(array $params): bool
{
Db::startTrans();
try {
$order= BeforehandOrder::where('id',$params['id'])->find();
$cart_info=BeforehandOrderCartInfo::where('bhoid',$params['id'])->select()->toArray();
$cartId = [];
foreach ($cart_info as $k => $v) {
$v['uid'] = $params['user_id'];
$v['store_id'] = $params['store_id'];
$find=StoreBranchProduct::where('store_id', $params['store_id'])->where('product_id', $v['product_id'])->find();
if(!$find){
$product=StoreProduct::where('id', $v['product_id'])->find();
$find=StoreProductLogic::ordinary($product, $params['store_id'], 0, $product);
}
if(in_array($order['order_type'],[2,3])){
if(isset($v['purchase']) && $v['purchase'] > 0){
$purchase = $v['purchase'];
}else{
$purchase=$v['price'];
}
$find->save(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $purchase]);
}
unset($v['id']);
$cart = CartLogic::add($v);
$cartId[] = $cart['id'];
}
$user = User::where('id', $params['user_id'])->find();
$params['shipping_type'] = 2;
$params['source'] =2;//后台下单
$res = OrderLogic::createOrder($cartId, null, $user, $params);
$order->order_sn=$res['order_id'];
$order->save();
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 编辑预订单表

View File

@ -212,6 +212,6 @@ class StoreOrderLogic extends BaseLogic
$detail['refund_price']=$refund_price;
CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id);
StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]);
StoreOrder::where('id', $detail['id'])->inc('refund_price',$refund_price)->inc('refund_num',$refund_num)->update();
}
}

View File

@ -26,6 +26,7 @@ class PurchaseProductOfferController extends BaseApiController
*/
public function lists()
{
$this->request->__set('uid',$this->userId);
return $this->dataLists(new PurchaseProductOfferLists());
}

View File

@ -18,7 +18,7 @@ use app\api\lists\BaseApiDataLists;
class PurchaseProductOfferLists extends BaseApiDataLists implements ListsSearchInterface
{
public $userId;
/**
* @notes 设置搜索条件
* @return \string[][]
@ -44,6 +44,12 @@ class PurchaseProductOfferLists extends BaseApiDataLists implements ListsSearchI
*/
public function lists(): array
{
$uid=$this->request->__get('uid');
if($uid){
$this->searchWhere[]=['buyer_id','=',$uid];
}else{
return [];
}
return PurchaseProductOffer::where($this->searchWhere)
->field(['id', 'order_id', 'product_id', 'price', 'buyer_nums', 'unit', 'is_buyer', 'buyer_confirm','need_num', 'buyer_id', 'status', ])
->limit($this->limitOffset, $this->limitLength)
@ -81,7 +87,11 @@ class PurchaseProductOfferLists extends BaseApiDataLists implements ListsSearchI
*/
public function count(): int
{
return PurchaseProductOffer::where($this->searchWhere)->count();
if($this->userId){
return 0;
}else{
return PurchaseProductOffer::where($this->searchWhere)->count();
}
}
}