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

Reviewed-on: #503
This commit is contained in:
mkm 2025-02-06 09:57:32 +08:00
commit 71dd95086d
10 changed files with 412 additions and 47 deletions

View File

@ -0,0 +1,46 @@
<?php
namespace app\admin\controller\accounts_receivable;
use app\admin\controller\BaseAdminController;
use app\admin\lists\AccountsReceivableLists;
use app\admin\logic\AccountsReceivableLogic;
use app\admin\validate\app_update\AppUpdateValidate;
/**
* Class AccountsReceivableController
* @package app\admin\controller\accounts_receivable
*/
class AccountsReceivableController extends BaseAdminController
{
public function lists()
{
return $this->dataLists(new AccountsReceivableLists());
}
public function edit()
{
$params = (new AppUpdateValidate())->post()->goCheck('edit');
$result = AccountsReceivableLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(AccountsReceivableLogic::getError());
}
public function delete()
{
$params = (new AppUpdateValidate())->post()->goCheck('delete');
AccountsReceivableLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
public function detail()
{
$params = (new AppUpdateValidate())->goCheck('detail');
$result = AccountsReceivableLogic::detail($params);
return $this->data($result);
}
}

View File

@ -8,6 +8,7 @@ use app\admin\lists\beforehand_order\BeforehandOrderLists;
use app\admin\lists\beforehand_order\BeforehandOrderTwoLists;
use app\admin\lists\beforehand_order\BeforehandOrderThreeLists;
use app\admin\logic\beforehand_order\BeforehandOrderLogic;
use app\admin\logic\purchase_product_offer\PurchaseProductOfferLogic;
use app\common\model\beforehand_order\BeforehandOrder;
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
use app\common\model\store_order\StoreOrder;
@ -83,7 +84,11 @@ class BeforehandOrderController extends BaseAdminController
'regional_manager' => $params['regional_manager'] ?? '',
];
$params['other_data'] = $other_data;
$result = BeforehandOrderLogic::add($params);
if ($params['order_type'] == 7) {
PurchaseProductOfferLogic::batchCreate($params);
} else {
BeforehandOrderLogic::add($params);
}
return $this->success('添加成功', [], 1, 1);
}
/**

View File

@ -0,0 +1,72 @@
<?php
namespace app\admin\lists;
use app\common\lists\ListsSearchInterface;
use app\common\model\beforehand_order\BeforehandOrder;
use app\common\model\finance\AccountsReceivable;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
use Illuminate\Contracts\Cache\Store;
/**
* AccountsReceivableLists
* Class AccountsReceivableLists
* @package app\admin\lists
*/
class AccountsReceivableLists extends BaseAdminDataLists implements ListsSearchInterface
{
public function setSearch(): array
{
return [
'=' => ['store_id', 'user_id'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function lists(): array
{
$query = AccountsReceivable::where($this->searchWhere);
if (!empty($this->params['order_sn'])) {
$orderIds = BeforehandOrder::where('order_id', 'like', '%' . $this->params['order_sn'] . '%')->column('id');
$query->whereIn('order_id', $orderIds);
}
$list = $query->with('info')
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
$stores = SystemStore::field('id,name')->whereIn('id', array_column($list, 'store_id'))->select()->toArray();
$stores = reset_index($stores, 'id');
$orderInfo = BeforehandOrder::field('id,order_id')->whereIn('id', array_column($list, 'order_id'))->select()->toArray();
$orderInfo = reset_index($orderInfo, 'id');
$orderInfo = reset_index($orderInfo, 'id');
foreach ($list as &$item) {
$item['store_name'] = $stores[$item['store_id']]['name'];
$item['order_sn'] = $orderInfo[$item['order_id']]['order_id'];
}
return $list;
}
/**
* @notes 获取数量
* @return int
*/
public function count(): int
{
$query = AccountsReceivable::where($this->searchWhere);
if (!empty($this->params['order_sn'])) {
$orderIds = BeforehandOrder::where('order_id', 'like', '%' . $this->params['order_sn'] . '%')->column('id');
$query->whereIn('order_id', $orderIds);
}
return $query->count();
}
}

View File

@ -0,0 +1,122 @@
<?php
namespace app\admin\logic;
use app\common\model\ActivityZone;
use app\common\logic\BaseLogic;
use app\common\model\ActivityZoneForm;
use app\common\model\finance\AccountsReceivable;
use support\exception\BusinessException;
use think\facade\Db;
/**
* Class AccountsReceivableLogic
* @package app\admin\logic
*/
class AccountsReceivableLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $order
*/
public static function add(array $order)
{
$model = new AccountsReceivable();
$model->order_id = $order['id'];
$model->store_id = $order['store_id'];
$model->user_id = $order['uid'];
$model->deadline = time() + 86400 * 15;
$model->total_debt = $order['total_price'];
$model->surplus_debt = $order['total_price'];
$model->save();
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author admin
* @date 2024/12/20 10:52
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ActivityZone::where('id', $params['id'])->update([
'form_id' => $params['form_id'],
'product_id' => $params['product_id'],
]);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author admin
* @date 2024/12/20 10:52
*/
public static function delete(array $params): bool
{
return ActivityZone::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author admin
* @date 2024/12/20 10:52
*/
public static function detail($params): array
{
return ActivityZone::findOrEmpty($params['id'])->toArray();
}
public function addProduct($product)
{
$activityFormId1 = ActivityZoneForm::whereRaw('FIND_IN_SET(:cate_id,cate_ids)', ['cate_id' => $product['two_cate_id']])->column('id');
$activityFormId2 = ActivityZoneForm::whereRaw('FIND_IN_SET(:cate_id,cate_ids)', ['cate_id' => $product['cate_id']])->column('id');
$activityFormIds = array_unique(array_merge($activityFormId1, $activityFormId2));
foreach ($activityFormIds as $activityFormId) {
$activityZone = new ActivityZone();
$activityZone->form_id = $activityFormId;
$activityZone->product_id = $product['id'];
$activityZone->save();
}
}
public function updateProduct($productId, $product)
{
$product['id'] = $productId;
$formIds = ActivityZone::where('product_id', $productId)->column('form_id');
if (empty($formIds)) {
$this->addProduct($product);
return;
}
$forms = ActivityZoneForm::whereIn('id', $formIds)->select()->toArray();
foreach ($forms as $form) {
$cateIds = explode(',', $form['cate_ids']);
if (!in_array($product['two_cate_id'], $cateIds) && !in_array($product['cate_id'], $cateIds)) {
ActivityZone::where('product_id', $productId)->where('form_id', $form['id'])->update(['delete_time' => time()]);
}
$this->addProduct($product);
}
}
public function deleteProduct($productId)
{
ActivityZone::where('product_id', $productId)->update(['delete_time' => time()]);
}
}

View File

@ -2,6 +2,7 @@
namespace app\admin\logic\beforehand_order;
use app\admin\logic\AccountsReceivableLogic;
use app\admin\logic\store_branch_product\StoreBranchProductLogic;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\logic\warehouse_product\WarehouseProductLogic;
@ -29,6 +30,7 @@ use app\common\model\user_ship\UserShip;
use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\model\warehouse_product_return\WarehouseProductReturn;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use app\common\service\xlsx\OrderAllocation;
use app\common\service\xlsx\OrderInfo;
use app\common\service\xlsx\OrderList;
@ -92,13 +94,13 @@ class BeforehandOrderLogic extends BaseLogic
$datas[$k]['mark'] = $v['mark'] ?? '';
$datas[$k]['product_id'] = $v['product_id'];
$datas[$k]['uid'] = $uid;
$datas[$k]['marques'] = $v['marques'] ?? '';
$datas[$k]['store_info'] = $v['store_info'] ?? '';
$datas[$k]['after_sales'] = $v['after_sales'] ?? '';
$datas[$k]['loss'] = $v['loss'] ?? '';
// $datas[$k]['marques'] = $v['marques'] ?? '';
// $datas[$k]['store_info'] = $v['store_info'] ?? '';
// $datas[$k]['after_sales'] = $v['after_sales'] ?? '';
// $datas[$k]['loss'] = $v['loss'] ?? '';
$datas[$k]['unit'] = $v['unit'] ?? '';
$datas[$k]['gross_weight'] = $v['gross_weight'] ?? '';
$datas[$k]['net_weight'] = $v['net_weight'] ?? '';
// $datas[$k]['gross_weight'] = $v['gross_weight'] ?? '';
// $datas[$k]['net_weight'] = $v['net_weight'] ?? '';
$datas[$k]['cart_num'] = $v['nums'];
$datas[$k]['accept_num'] = $v['nums'];
$datas[$k]['is_buyer'] = $is_buyer;
@ -128,6 +130,7 @@ class BeforehandOrderLogic extends BaseLogic
'address' => $params['address'] ?? '',
'mark' => $params['mark'] ?? '',
'order_type' => $order_type,
'is_arrears' => $params['is_arrears'] ?? 1,
'other_data' => json_encode($params['other_data'], true)
]);
/** 添加审批记录 */
@ -137,27 +140,27 @@ class BeforehandOrderLogic extends BaseLogic
$datas[$k]['bhoid'] = $order['id'];
$data['id'] = $v['product_id'];
if ($v['marques'] != '') {
$data['marques'] = $v['marques'];
}
if ($v['store_info'] != '') {
$data['store_info'] = $v['store_info'];
}
if ($v['after_sales'] != '') {
$data['after_sales'] = $v['after_sales'];
}
if ($v['package'] != '') {
$data['package'] = $v['package'];
}
if ($v['loss'] != '') {
$data['loss'] = $v['loss'];
}
if ($v['gross_weight'] != '') {
$data['gross_weight'] = $v['gross_weight'];
}
if ($v['net_weight'] != '') {
$data['net_weight'] = $v['net_weight'];
}
// if ($v['marques'] != '') {
// $data['marques'] = $v['marques'];
// }
// if ($v['store_info'] != '') {
// $data['store_info'] = $v['store_info'];
// }
// if ($v['after_sales'] != '') {
// $data['after_sales'] = $v['after_sales'];
// }
// if ($v['package'] != '') {
// $data['package'] = $v['package'];
// }
// if ($v['loss'] != '') {
// $data['loss'] = $v['loss'];
// }
// if ($v['gross_weight'] != '') {
// $data['gross_weight'] = $v['gross_weight'];
// }
// if ($v['net_weight'] != '') {
// $data['net_weight'] = $v['net_weight'];
// }
$product_arr[] = $data;
}
(new StoreProduct())->saveAll($product_arr);
@ -373,11 +376,20 @@ class BeforehandOrderLogic extends BaseLogic
if ($order['outbound_id'] > 0) {
throw new BusinessException('该订单已创建出库单');
}
$info = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->select();
$info = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->select()->toArray();
// $product_column = array_column($info, 'product_id');
// $storege_arr=WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id','in',$product_column)->select();
foreach ($info as $k => $v) {
if ($v['pay_price'] <= 0) {
throw new BusinessException('商品价格为空 不能生成出库订单,对应id:' . $v['id']);
}
// foreach ($storege_arr as $key => $value) {
// if ($value['is_verify']==1 && $v['product_id'] == $value['product_id']) {
// if ($v['cart_num'] > $value['nums']) {
// throw new BusinessException('仓库库存不足 不能生成出库订单,对应id:' . $v['id']);
// }
// }
// }
}
$count = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->where('cart_num', 0)->count('id');
if ($count > 0) {
@ -442,6 +454,9 @@ class BeforehandOrderLogic extends BaseLogic
throw new BusinessException('出库失败,预订单更新出错');
}
BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->update(['is_buyer' => -1]);
if ($order['is_arrears'] == 2) {
AccountsReceivableLogic::add($order);
}
self::confirm(['id' => $params['bhoid']]);
Db::commit();
return true;

View File

@ -240,18 +240,18 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
$data['manufacture'] = $v['manufacture'] > 0 ? date('Y-m-d H:i:s', $v['manufacture']) : '';
$data['expiration_date'] = $v['expiration_date'] > 0 ? date('Y-m-d H:i:s', $v['expiration_date']) : '';
$product_arr=[];
if($v['package']!=''){
$product_arr['package']=$v['package'];
}
if($v['store_info']!=''){
$product_arr['store_info']=$v['store_info'];
}
if($v['marques']!=''){
$product_arr['marques']=$v['marques'];
}
if($v['after_sales']!=''){
$product_arr['after_sales']=$v['after_sales'];
}
// if($v['package']!=''){
// $product_arr['package']=$v['package'];
// }
// if($v['store_info']!=''){
// $product_arr['store_info']=$v['store_info'];
// }
// if($v['marques']!=''){
// $product_arr['marques']=$v['marques'];
// }
// if($v['after_sales']!=''){
// $product_arr['after_sales']=$v['after_sales'];
// }
if($product_arr!=[]){
StoreProduct::where('id',$v['product_id'])->save($product_arr);
}

View File

@ -84,10 +84,10 @@ class PurchaseProductOfferLogic extends BaseLogic
'need_num' => $params['need_num'],
'mark' => $mark,
'buyer_id' => $params['buyer_id'],
'package' => $find['package'],
'store_info' => $find['store_info'],
'marques' => $find['marques'],
'after_sales' => $find['after_sales'],
// 'package' => $find['package'],
// 'store_info' => $find['store_info'],
// 'marques' => $find['marques'],
// 'after_sales' => $find['after_sales'],
'status' => 0,
'source_order_info' => [
[
@ -488,4 +488,73 @@ class PurchaseProductOfferLogic extends BaseLogic
}
return $res;
}
public static function batchCreate($params)
{
if (empty($params['buyer_id'])) {
throw new BusinessException('请选择采购员');
}
Db::startTrans();
try {
$procurementOrder = new BeforehandOrder();
$procurementOrder->order_id = getNewOrderId('CG');
$procurementOrder->buyer_id = $params['buyer_id'];
$procurementOrder->admin_id = $params['admin_id'];
$procurementOrder->order_type = 7;
$procurementOrder->total_price = 0;
$procurementOrder->pay_price = 0;
$procurementOrder->save();
$purchaseOffer = [];
$cartInfo = [];
foreach ($params['product_arr'] as $product) {
if ($product['product_id'] <= 0) {
continue;
}
$cartInfo[] = [
'bhoid' => $procurementOrder['id'],
'product_id' => $product['product_id'],
'unit' => $product['unit'],
'cart_num' => $product['nums'],
'accept_num' => $product['nums'],
'mark' => $product['mark'],
'is_buyer' => 1,
'procurement_order_id' => $procurementOrder['id'],
'total_price' => bcmul($product['price'], $product['nums'], 2),
'pay_price' => bcmul($product['price'], $product['nums'], 2),
'purchase' => $product['purchase'],
'uid' => $params['uid'],
'price' => $product['price'],
'package' => $product['package'],
'create_time' => time(),
'update_time' => time(),
];
$purchaseOffer[] = [
'order_id' => $procurementOrder['id'],
'product_id' => $product['product_id'],
'unit' => $product['unit'],
'is_buyer' => 1,
'need_num' => $product['nums'],
'mark' => $product['mark'],
'buyer_id' => $params['buyer_id'],
'status' => 0,
'source_order_info' => [
[
'source_order_id' => $procurementOrder['id'],
'product_id' => $product['product_id'],
'need_num' => $product['nums'],
'mark' => $product['mark'],
]
]
];
}
PurchaseProductOffer::insertAll($purchaseOffer);
BeforehandOrderCartInfo::insertAll($cartInfo);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
}

View File

@ -501,8 +501,10 @@ class PayNotifyLogic extends BaseLogic
if ($order['other_uid'] > 0) {
$uid = $order['other_uid'];
}
$cashFlowLogic = new CashFlowLogic();
$cashFlowLogic->insert($order['store_id'], $order['price'], $orderSn);
if ($type != 'wechat') {
$cashFlowLogic = new CashFlowLogic();
$cashFlowLogic->insert($order['store_id'], $order['price'], $orderSn);
}
PushService::push('wechat_mmp_' . $uid, $uid, ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]);
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]);

View File

@ -0,0 +1,20 @@
<?php
namespace app\common\model\finance;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
class AccountsReceivable extends BaseModel
{
use SoftDelete;
protected $deleteTime = 'delete_time';
// 不生成该表的日志
public $doNotRecordLog = true;
public function info()
{
return $this->hasMany(AccountsReceivableInfo::class, 'accounts_receivable_id', 'id');
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace app\common\model\finance;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
class AccountsReceivableInfo extends BaseModel
{
use SoftDelete;
protected $deleteTime = 'delete_time';
// 不生成该表的日志
public $doNotRecordLog = true;
}