新增采购列表导出功能并优化相关逻辑
- 在 PurchaseProductOfferLists 类中实现了 ListsExcelInterface 接口,添加了导出功能 - 修改了 BeforehandOrderLogic 类中的订单处理逻辑,优化了订单创建和导出流程 - 调整了 OrderLogic 和 UserLogic 类中的一些冗余代码,提高了代码的可读性和性能
This commit is contained in:
parent
71730e9bd9
commit
83c5d2c84b
@ -4,9 +4,11 @@ namespace app\admin\lists\purchase_product_offer;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\lists\ListsExcelInterface;
|
||||
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\delivery_service\DeliveryService;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\supplier\Supplier;
|
||||
@ -16,7 +18,7 @@ use app\common\model\supplier\Supplier;
|
||||
* Class PurchaseProductOfferLists
|
||||
* @package app\admin\listspurchase_product_offer
|
||||
*/
|
||||
class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
|
||||
{
|
||||
|
||||
|
||||
@ -46,15 +48,16 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc
|
||||
public function lists(): array
|
||||
{
|
||||
return PurchaseProductOffer::where($this->searchWhere)
|
||||
->field(['id', 'supplier_id', 'order_id', 'product_id', 'price','total_price', 'buyer_nums', 'unit', 'is_buyer', 'buyer_confirm', 'is_storage', 'is_stream', 'need_num', 'notes', 'buyer_id', 'status', 'stream_admin_id', 'stream_time', 'storage_admin_id'])
|
||||
->field(['id', 'supplier_id', 'order_id', 'product_id', 'price','total_price', 'buyer_nums', 'unit', 'is_buyer', 'buyer_confirm', 'is_storage', 'is_stream', 'need_num', 'mark', 'buyer_id', 'status', 'stream_admin_id', 'stream_time', 'storage_admin_id'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($item){
|
||||
$find=StoreProduct::where('id',$item->product_id)->find();
|
||||
$find=StoreProduct::where('id',$item->product_id)->withTrashed()->find();
|
||||
$item->store_name=$find->store_name;
|
||||
$item->store_info=$find->store_info;
|
||||
$item->image=$find->image;
|
||||
$item->unit_name=StoreProductUnit::where('id',$item->unit)->value('name');
|
||||
$item->cate_name=StoreCategory::where('id',$find->cate_id)->value('name');
|
||||
if($item->is_buyer==1){
|
||||
$item->is_buyer_name='需要采购';
|
||||
}elseif($item->is_buyer==-1){
|
||||
@ -67,6 +70,8 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc
|
||||
}else{
|
||||
$item->buyer_confirm_name='采购完成';
|
||||
}
|
||||
}else{
|
||||
$item->buyer_name='';
|
||||
}
|
||||
if($item->supplier_id>0){
|
||||
$item->supplier_name=Supplier::where('id',$item->supplier_id)->value('mer_name');
|
||||
@ -95,4 +100,33 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc
|
||||
return PurchaseProductOffer::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 导出文件名
|
||||
* @return string
|
||||
* @author 乔峰
|
||||
* @date 2022/11/24 16:17
|
||||
*/
|
||||
public function setFileName(): string
|
||||
{
|
||||
return '采购列表';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 导出字段
|
||||
* @return string[]
|
||||
* @author 乔峰
|
||||
* @date 2022/11/24 16:17
|
||||
*/
|
||||
public function setExcelFields(): array
|
||||
{
|
||||
$data=[
|
||||
'store_name' => '商品名称',
|
||||
'unit_name' => '单位',
|
||||
'cate_name' => '分类',
|
||||
'need_num' => '数量',
|
||||
'buyer_name' => '采购人',
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -13,7 +13,9 @@ 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\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserAddress;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use support\exception\BusinessException;
|
||||
@ -45,7 +47,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
$total_price = 0;
|
||||
$uid = $params['uid'] ?? 0;
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$datas[$k]['mark'] = $v['mark']??'';
|
||||
$datas[$k]['mark'] = $v['mark'] ?? '';
|
||||
$datas[$k]['product_id'] = $v['product_id'];
|
||||
$datas[$k]['uid'] = $uid;
|
||||
$datas[$k]['cart_num'] = $v['nums'];
|
||||
@ -92,39 +94,138 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order= BeforehandOrder::where('id',$params['id'])->find();
|
||||
$cart_info=BeforehandOrderCartInfo::where('bhoid',$params['id'])->select()->toArray();
|
||||
$cartId = [];
|
||||
$order = BeforehandOrder::where('id', $params['id'])->find();
|
||||
$cart_info = BeforehandOrderCartInfo::where('bhoid', $params['id'])->select()->toArray();
|
||||
|
||||
$cart_select = [];
|
||||
$total_price = 0;
|
||||
$pay_price = 0;
|
||||
$cost_price = 0;
|
||||
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);
|
||||
$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){
|
||||
if (in_array($order['order_type'], [2, 3])) {
|
||||
if (isset($v['purchase']) && $v['purchase'] > 0) {
|
||||
$purchase = $v['purchase'];
|
||||
}else{
|
||||
$purchase=$v['price'];
|
||||
} 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'];
|
||||
|
||||
$cart_select[$k]['price'] = $v['price'];
|
||||
$cart_select[$k]['cost'] = $find['cost'];
|
||||
$cart_select[$k]['vip'] = 0;
|
||||
$cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name') ?? ''; //单位名称
|
||||
|
||||
//利润
|
||||
$cart_select[$k]['total_purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本
|
||||
$cart_select[$k]['pay_price'] = $v['total_price']; //订单支付金额
|
||||
$cart_select[$k]['total_price'] = $v['total_price']; //订单支付金额
|
||||
$cart_select[$k]['store_price'] = 0; //商户价
|
||||
$cart_select[$k]['vip_price'] = 0; //vip售价
|
||||
$cart_select[$k]['product_id'] = $v['product_id'];
|
||||
$cart_select[$k]['old_cart_id'] = 0;
|
||||
$cart_select[$k]['cart_num'] = convertStringToNumber($v['cart_num']);
|
||||
$cart_select[$k]['verify_code'] = '';
|
||||
$cart_select[$k]['vip_frozen_price'] = 0;
|
||||
$cart_select[$k]['store_info'] = $find['store_info'];
|
||||
$cart_select[$k]['rose'] = $find['rose'];
|
||||
|
||||
$cartInfo = $cart_select[$k];
|
||||
$cartInfo['name'] = $find['store_name'];
|
||||
$cartInfo['image'] = $find['image'];
|
||||
$cart_select[$k]['cart_info'] = json_encode($cartInfo);
|
||||
//理论上每笔都是拆分了
|
||||
$cart_select[$k]['name'] = $find['store_name'];
|
||||
if ($find['purchase'] < $v['price']) {
|
||||
$cart_select[$k]['purchase'] = $find['purchase'];
|
||||
} else {
|
||||
$cart_select[$k]['purchase'] = $v['price'];
|
||||
}
|
||||
$cart_select[$k]['store_id'] = $params['store_id'] ?? 0;
|
||||
|
||||
$total_price = bcadd($total_price, $v['total_price'], 2);
|
||||
$pay_price = bcadd($pay_price, $v['total_price'], 2);
|
||||
$cost_price = bcadd($pay_price, $cart_select[$k]['total_purchase'], 2);
|
||||
}
|
||||
$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_id = getNewOrderId('PF');
|
||||
$code = rand(1, 10) . '-' . substr($order_id, -5);
|
||||
|
||||
$uid = $user['id'];
|
||||
$_order = [
|
||||
'order_id' => $order_id,
|
||||
'total_price' => $total_price, //总价
|
||||
'cost' => $cost_price, //成本价1-
|
||||
'pay_price' => $pay_price, //支付价
|
||||
'vip_price' => 0,
|
||||
'total_num' => count($cart_select), //总数
|
||||
'pay_type' => $params['pay_type'] ?? 0,
|
||||
'reservation_time' => null,
|
||||
'cart_id' => '',
|
||||
'store_id' => $params['store_id'] ?? 0,
|
||||
'shipping_type' => 2, //配送方式 1=快递 ,2=门店自提
|
||||
'deduction_price' => 0, //抵扣金额
|
||||
'source' => 2, //后台下单
|
||||
'is_storage' => 0,
|
||||
'verify_code' => createCode($code),
|
||||
];
|
||||
if ($_order['pay_price'] == 0) {
|
||||
throw new BusinessException('支付金额不能为0');
|
||||
}
|
||||
$_order['uid'] = $uid;
|
||||
$_order['spread_uid'] = 0;
|
||||
$_order['mark'] = '';
|
||||
$_order['real_name'] = $user['real_name'];
|
||||
$_order['user_phone'] = $user['mobile'];
|
||||
$_order['pay_type'] = $params['pay_type'];
|
||||
$_order['reservation_time'] = null;
|
||||
$_order['reservation'] = 0;
|
||||
$_order['status'] = 1;
|
||||
|
||||
if ($uid > 0) {
|
||||
$address = UserAddress::where(['uid' => $uid])->find();
|
||||
if ($address) {
|
||||
if ($address['area']) {
|
||||
$_order['user_address'] = Db::name('geo_area')->where('area_code', $address['area'])->value('area_name') ?? '';
|
||||
}
|
||||
if ($address['street']) {
|
||||
$street_name = Db::name('geo_street')->where('street_code', $address['street'])->value('street_name') ?? '';
|
||||
$_order['user_address'] .= '/' . $street_name;
|
||||
}
|
||||
if ($address['village']) {
|
||||
$village_name = Db::name('geo_village')->where('village_code', $address['village'])->value('village_name') ?? '';
|
||||
$_order['user_address'] .= '/' . $village_name;
|
||||
}
|
||||
if ($address['brigade']) {
|
||||
$_order['user_address'] .= '/' . $address['brigade'] ?? $address['brigade'] . '队';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$res = StoreOrder::create($_order);
|
||||
|
||||
foreach ($cart_select as $k => $v) {
|
||||
$cart_select[$k]['oid'] = $res->id;
|
||||
$cart_select[$k]['uid'] = $uid;
|
||||
$cart_select[$k]['cart_id'] = 0;
|
||||
}
|
||||
(new StoreOrderCartInfo())->saveAll($cart_select);
|
||||
|
||||
$order->order_sn = $res['order_id'];
|
||||
$order->save();
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
d($e);
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
@ -243,8 +344,8 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
try {
|
||||
$datas = [];
|
||||
|
||||
$order=StoreOrder::where('id', $params['id'])->find();
|
||||
$info=StoreOrderCartInfo::where('oid', $params['id'])->select();
|
||||
$order = StoreOrder::where('id', $params['id'])->find();
|
||||
$info = StoreOrderCartInfo::where('oid', $params['id'])->select();
|
||||
$total_num = $order['total_num'];
|
||||
$total_price = $order['total_price'];
|
||||
$uid = $order['uid'];
|
||||
|
@ -185,7 +185,6 @@ class OrderLogic extends BaseLogic
|
||||
$cart_select[$k]['purchase'] = $find['purchase'];
|
||||
$cart_select[$k]['imgs'] = $find['image'];
|
||||
$cart_select[$k]['store_id'] = $params['store_id'] ?? 0;
|
||||
$cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name');
|
||||
$cart_select[$k]['total_price'] = $cart_select[$k]['pay_price'];
|
||||
self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2);
|
||||
self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2);
|
||||
@ -298,11 +297,7 @@ class OrderLogic extends BaseLogic
|
||||
$_order['verify_code'] = $verify_code;
|
||||
$_order['reservation_time'] = null;
|
||||
$_order['reservation'] = 0;
|
||||
$params['reservation'] ?? 0; //是否需要预约
|
||||
// if (isset($params['reservation_time']) && $params['reservation_time']) {
|
||||
// $_order['reservation_time'] = $params['reservation_time'];
|
||||
// $_order['reservation'] = YesNoEnum::YES;
|
||||
// }
|
||||
|
||||
if ($uid > 0) {
|
||||
$address = UserAddress::where(['uid' => $uid])->find();
|
||||
if ($address) {
|
||||
@ -328,13 +323,7 @@ class OrderLogic extends BaseLogic
|
||||
if ($_order['pay_type'] == PayEnum::BALANCE_PAY && $user != null && $user['now_money'] < $_order['pay_price']) {
|
||||
throw new BusinessException('余额不足');
|
||||
}
|
||||
//生成核销码
|
||||
// $generator = new BarcodeGeneratorPNG();
|
||||
// $barcode = $generator->getBarcode($verify_code, $generator::TYPE_CODE_128);
|
||||
// $findPath = '/image/barcode/' . time() . '.png';
|
||||
// $savePath = public_path() . $findPath;
|
||||
// file_put_contents($savePath, $barcode);
|
||||
// $_order['verify_img'] = $findPath;
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = StoreOrder::create($_order);
|
||||
|
@ -101,12 +101,12 @@ class UserLogic extends BaseLogic
|
||||
$data['next_limit'] = $new['limit'] - $data['total_recharge_amount'];
|
||||
}
|
||||
$data['is_staff'] = 0;
|
||||
if(isset($data['mobile']) && $data['mobile']){
|
||||
$check = DeliveryService::where('phone',$data['mobile'])->find()??[];
|
||||
if ($check){
|
||||
$data['is_staff'] = 1;
|
||||
}
|
||||
}
|
||||
// if(isset($data['mobile']) && $data['mobile']){
|
||||
// $check = DeliveryService::where('phone',$data['mobile'])->find()??[];
|
||||
// if ($check){
|
||||
// $data['is_staff'] = 1;
|
||||
// }
|
||||
// }
|
||||
$data['label_name']=UserLabel::where('label_id',$data['label_id'])->value('label_name');
|
||||
$data['return_money'] = Db::name('vip_flow')->
|
||||
where(['user_id'=>$uid,'status'=>0])
|
||||
|
Loading…
x
Reference in New Issue
Block a user