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

Reviewed-on: #142
This commit is contained in:
mkm 2024-08-19 21:02:30 +08:00
commit 1328fe3c09
16 changed files with 216 additions and 85 deletions

View File

@ -72,6 +72,7 @@ class InventoryTransferController extends BaseAdminController
*/
public function delete()
{
return $this->fail('删除功能暂未开放');
$params = (new InventoryTransferValidate())->post()->goCheck('delete');
InventoryTransferLogic::delete($params);
return $this->success('删除成功', [], 1, 1);

View File

@ -0,0 +1,39 @@
<?php
namespace app\admin\controller\purchase_order_info;
use app\admin\controller\BaseAdminController;
use app\admin\logic\purchase_order_info\PurchaseOrderInfoLogic;
/**
* 采购订单详情控制器
* Class PurchaseOrderInfoController
* @package app\admin\controller\purchase_order_info
*/
class PurchaseOrderInfoController extends BaseAdminController
{
/**
* @notes 编辑采购供应链商品
* @return \think\response\Json
* @author admin
* @date 2024/08/14 15:06
*/
public function edit()
{
$params = $this->request->post();
switch ($params['type']) {
case 'buyer':
PurchaseOrderInfoLogic::buyer($params);
break;
default:
return $this->fail('参数错误');
break;
}
if (PurchaseOrderInfoLogic::hasError()) {
return $this->fail(PurchaseOrderInfoLogic::getError());
}
return $this->success('设置成功', [], 1, 1);
}
}

View File

@ -70,20 +70,27 @@ class InventoryTransferLists extends BaseAdminDataLists implements ListsSearchIn
}
return InventoryTransfer::where($this->searchWhere)
->field(['id', 'product_id', 'nums', 'one_before_nums', 'one_after_nums','two_before_nums','two_after_nums', 'type', 'one_id', 'two_id', 'create_time'])
->field(['id', 'product_id', 'nums', 'one_before_nums', 'one_after_nums','two_before_nums','two_after_nums', 'one_type','two_type', 'one_id', 'two_id', 'create_time'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$item->store_name= StoreProduct::where('id',$item->product_id)->value('store_name');
if($item->type==1){
$item->type_name='商户';
$type_name='';
if($item->one_type==1){
$item->one_name=SystemStore::where('id',$item->one_id)->value('name');
$type_name='门店转';
}else{
$item->one_name=Warehouse::where('id',$item->one_id)->value('name');
$type_name='仓库转';
}
if($item->two_type==1){
$type_name.='门店';
$item->two_name=SystemStore::where('id',$item->two_id)->value('name');
}else{
$item->type_name='仓库';
$item->one_name=Warehouse::where('id',$item->one_id)->value('name');
$type_name.='仓库';
$item->two_name=Warehouse::where('id',$item->two_id)->value('name');
}
$item->type_name=$type_name;
$item->store_name= StoreProduct::where('id',$item->product_id)->value('store_name');
})
->toArray();

View File

@ -6,6 +6,7 @@ namespace app\admin\lists\purchase_order_info;
use app\admin\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\purchase_order_info\PurchaseOrderInfo;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\system_store\SystemStore;
@ -48,13 +49,22 @@ class PurchaseOrderInfoLists extends BaseAdminDataLists implements ListsSearchIn
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {
$find=StoreProduct::where('id',$item->product_id)->field('store_info,unit,store_name,image')->find();
$find=StoreBranchProduct::where('product_id',$item->product_id)->where('store_id',$item->store_id)->field('store_info,stock,unit,store_name,image')->find();
if($find){
$item->store_name=$find->store_name;
$item->unit_name=StoreProductUnit::where('id',$find->unit)->value('name');
$item->unit=$find->unit;
$item->stock=$find->stock;
$item->store_info=$find->store_info;
$item->image=$find->image;
}
if($item->is_buyer==1){
$item->is_buyer_name='需采购';
}elseif($item->is_buyer==-1){
$item->is_buyer_name='不采购';
}else{
$item->is_buyer_name='未知';
}
switch ($item->storage) {
case 0:
$item->storage_name = '未入库';

View File

@ -2,7 +2,7 @@
namespace app\admin\logic\inventory_transfer;
use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\common\model\inventory_transfer\InventoryTransfer;
use app\common\logic\BaseLogic;
use app\common\model\store_branch_product\StoreBranchProduct;
@ -32,33 +32,43 @@ class InventoryTransferLogic extends BaseLogic
$one_after_nums = 0;
$two_before_nums = 0;
$two_after_nums = 0;
if ($params['type'] == 1) {
if($params['one_type']==1){
$stock = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['one_id'])->value('stock');
$stock_two = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->value('stock');
if ($stock < $params['nums']) {
self::setError('调拨数量不能大于当前门店库存');
return false;
} else {
}
if($params['two_type']==1){
$stock_two = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->value('stock');
}elseif($params['two_type']==2){
$stock_two = WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['two_id'])->value('nums');
}
$one_before_nums = $stock;
$one_after_nums = bcsub($stock, $params['nums']);
$two_before_nums = $stock_two;
$two_after_nums = bcadd($stock_two, $params['nums']);
}
} elseif ($params['type'] == 2) {
}elseif($params['one_type']==2){
$stock = WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['one_id'])->value('nums');
$stock_two = WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['two_id'])->value('nums');
if ($stock < $params['nums']) {
self::setError('调拨数量不能大于当前仓库库存');
return false;
} else {
}
if($params['two_type']==1){
$stock_two = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->value('stock');
}elseif($params['two_type']==2){
$stock_two = WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['two_id'])->value('nums');
}
$one_before_nums = $stock;
$one_after_nums = bcsub($stock, $params['nums']);
$two_before_nums = $stock_two;
$two_after_nums = bcadd($stock_two, $params['nums']);
}else{
self::setError('调拨类型错误');
return false;
}
}
Db::startTrans();
try {
InventoryTransfer::create([
@ -68,20 +78,24 @@ class InventoryTransferLogic extends BaseLogic
'one_after_nums' => $one_after_nums,
'two_before_nums' => $two_before_nums,
'two_after_nums' => $two_after_nums,
'type' => $params['type'],
'one_type' => $params['one_type'],
'two_type' => $params['two_type'],
'one_id' => $params['one_id'],
'two_id' => $params['two_id']
]);
if ($params['type'] == 1) {
if($params['one_type']==1){
StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['one_id'])->dec('stock', $params['nums'])->update();
StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->inc('stock', $params['nums'])->update();
} elseif ($params['type'] == 2) {
} elseif ($params['one_type'] == 2) {
WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['one_id'])->dec('nums', $params['nums'])->update();
}
if($params['two_type']==1){
StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->inc('stock', $params['nums'])->update();
} elseif ($params['two_type'] == 2) {
WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['two_id'])->inc('nums', $params['nums'])->update();
}
Db::commit();
return true;
} catch (\Exception $e) {
} catch (\Throwable $e) {
Db::rollback();
self::setError($e->getMessage());
return false;

View File

@ -112,18 +112,18 @@ class PurchaseOrderLogic extends BaseLogic
$purchase_order_info_two[] = $arr;
}
$purchaseOrderInfo->saveAll($purchase_order_info_two);
$productOffer = [];
foreach ($info as $item) {
$arr['order_id'] = $res['id'];
$arr['product_id'] = $item['product_id'];
$arr['price'] = $item['price'];
$arr['total_price'] = $item['total_price'];
$arr['need_num'] = $item['cart_num'];
$arr['unit'] = StoreProduct::where('id', $item['product_id'])->value('unit');
$productOffer[] = $arr;
}
$purchaseProductOffer = new PurchaseProductOffer();
$purchaseProductOffer->saveAll($productOffer);
// $productOffer = [];
// foreach ($info as $item) {
// $arr['order_id'] = $res['id'];
// $arr['product_id'] = $item['product_id'];
// $arr['price'] = $item['price'];
// $arr['total_price'] = $item['total_price'];
// $arr['need_num'] = $item['cart_num'];
// $arr['unit'] = StoreProduct::where('id', $item['product_id'])->value('unit');
// $productOffer[] = $arr;
// }
// $purchaseProductOffer = new PurchaseProductOffer();
// $purchaseProductOffer->saveAll($productOffer);
// StoreOrder::whereIn('id', $oid_arr)->update(['is_merge' => 1]);
// Db::commit();
// return true;

View File

@ -0,0 +1,44 @@
<?php
namespace app\admin\logic\purchase_order_info;
use app\common\logic\BaseLogic;
use app\common\model\purchase_order_info\PurchaseOrderInfo;
use app\common\model\purchase_product_offer\PurchaseProductOffer;
use app\common\model\store_product\StoreProduct;
use think\facade\Db;
class PurchaseOrderInfoLogic extends BaseLogic
{
/**
* 是否需采购
*/
public static function buyer($params)
{
$data['is_buyer'] = $params['is_buyer'];
Db::startTrans();
try {
if ($params['is_buyer'] == 1&& $params['poid']>0) {
$data['buyer_nums'] = $params['buyer_nums'];
$find = PurchaseProductOffer::where('order_id', $params['poid'])->where('product_id', $params['product_id'])->find();
if ($find) {
PurchaseProductOffer::where('id', $find['id'])->inc('buyer_nums', $params['buyer_nums'])->update();
} else {
$arr['order_id'] = $params['poid'];
$arr['product_id'] = $params['product_id'];
$arr['need_num'] = $params['cart_num'];
$arr['buyer_nums'] = $params['buyer_nums'];
$arr['unit'] = StoreProduct::where('id', $params['product_id'])->value('unit');
PurchaseProductOffer::create($arr);
}
}
PurchaseOrderInfo::where('id', $params['id'])->update($data);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\purchase_product_offer;
use app\common\model\purchase_product_offer\PurchaseProductOffer;
use app\common\logic\BaseLogic;
use app\common\model\delivery_service\DeliveryService;
use think\facade\Db;
@ -103,15 +104,17 @@ class PurchaseProductOfferLogic extends BaseLogic
*/
public static function buyer($params)
{
Db::startTrans();
try {
$data=[
'is_buyer' => $params['is_buyer'],
];
if($params['is_buyer']==1){
if($params['buyer_id']==''){
self::setError('采购人不能为空');
return false;
}
$data['buyer_id']=$params['buyer_id'];
$data['buyer_nums']=$params['buyer_nums'];
}
Db::startTrans();
try {
$data['is_buyer']=$params['is_buyer'];
PurchaseProductOffer::where('id', $params['id'])->update($data);
Db::commit();
return true;

View File

@ -50,7 +50,7 @@ class InventoryTransferValidate extends BaseValidate
*/
public function sceneAdd()
{
return $this->only(['product_id','nums','type','one_id','two_id']);
return $this->only(['product_id','nums','one_id','two_id']);
}

View File

@ -207,11 +207,27 @@ class IndexController extends BaseApiController
*/
public function config()
{
//处理返回最近的店铺
$params=$this->request->get();
if ((isset($params['lat']) && $params['lat'] != '') && (isset($params['long']) && $params['long'] != '')) {
$latitude = $params['lat'];
$longitude = $params['long'];
// 计算距离的SQL表达式
$distanceSql = "SQRT(POW(69.1 * (latitude - {$latitude}), 2) +
POW(69.1 * ({$longitude} - longitude) * COS(latitude / 57.3), 2))";
$find = SystemStore::field("id, name,abbreviation, {$distanceSql} AS distance")
->where('latitude', '<>', '')
->where('longitude', '<>', '')
->order('distance', 'asc') // 根据距离排序
->find();
} else {
$store_id = getenv('STORE_ID') ?? 1;
$find = SystemStore::where('id', $store_id)->find();
}
$list = [
'id' => $find['id'],
'store_name' => $find['name'],
'abbreviation' => $find['abbreviation'],
];
return $this->success('ok', $list);
}

View File

@ -68,7 +68,8 @@ class UserController extends BaseApiController
// ]
public function info()
{
return $this->success('success', UserLogic::info($this->userId));
$params=$this->request->post();
return $this->success('success', UserLogic::info($this->userId,$params));
}
// #[

View File

@ -35,7 +35,7 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
*/
public function setSearch(): array
{
return [];
return ['='=>['store_id']];
}

View File

@ -58,7 +58,7 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac
$data = SystemStore::where($this->searchWhere)->where($where)
->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show',
'day_time','is_store','latitude','longitude','day_start','day_end','is_store'
,'is_send'
,'is_send','abbreviation'
])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])

View File

@ -66,6 +66,11 @@ class OrderLogic extends BaseLogic
*/
static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = [], $createOrder = 0)
{
if(empty($params['store_id']) || $params['store_id'] <= 0){
self::setError('请选择门店');
return false;
}
$where = ['is_pay' => 0];
$cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray();
if (empty($cart_select)) {
@ -84,9 +89,9 @@ class OrderLogic extends BaseLogic
self::$fresh_price = 0; //生鲜金额
/** 计算价格 */
$off_activity = Config::where('name', 'off_activity')->value('value');
$field = 'id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose';
$field = 'product_id id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose';
foreach ($cart_select as $k => $v) {
$find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find();
$find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field($field)->find();
if (!$find) {
self::setError('商品不存在');
return false;
@ -114,7 +119,8 @@ class OrderLogic extends BaseLogic
$price = $find['cost'];
} else {
$price = $find['price'];
if (isset($params['store_id']) && $params['store_id'] == getenv('ACTIVITY_STORE_ID')) {
//单门店活动判断
if ($params['store_id'] == getenv('ACTIVITY_STORE_ID')) {
$storeBranchPrice = StoreBranchProduct::where('store_id', getenv('ACTIVITY_STORE_ID'))->where('product_id', $v['product_id'])->value('price');
if ($storeBranchPrice) {
$price = $storeBranchPrice;
@ -227,30 +233,14 @@ class OrderLogic extends BaseLogic
if (isset($params['source']) && $params['source'] > 0) {
$order['source'] = $params['source'];
}
//处理返回最近的店铺
if ((isset($params['lat']) && $params['lat'] != '') && (isset($params['long']) && $params['long'] != '')) {
$storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray();
$nearestStore = null;
$minDistance = PHP_FLOAT_MAX;
foreach ($storeAll as $value) {
$value['distance'] = haversineDistance($value['latitude'], $value['longitude'], $params['lat'], $params['long']);
if ($value['distance'] < $minDistance) {
$minDistance = $value['distance'];
$nearestStore = $value;
}
}
$store['near_store'] = [];
if ($nearestStore) {
$store['near_store'] = $nearestStore;
}
} else {
if (isset($params['store_id']) && $params['store_id'] > 0) {
$store_id = $params['store_id'];
} else {
$store_id = getenv('STORE_ID') ?? 1;
}
$store['near_store'] = SystemStore::where('id', $store_id)->field('id,name,phone,address,detailed_address,latitude,longitude')->find() ?? [];
}
if ($user) {
$order['address_id'] = UserAddress::where('uid', $user['id'])->where('is_default', 1)->value('id') ?? 0;
}
@ -264,13 +254,13 @@ class OrderLogic extends BaseLogic
// 使用DateTime::format()方法获取时间并比较
if ($currentTime->format('H:i') > $fourPM->format('H:i')) {
$currentDate = date('Y-m-d');
$alert='当前时间超过配送截止时间16:00,若下单,物品送达时间为'.date('Y-m-d', strtotime($currentDate. '+2 days'));
$alert = '当前时间超过配送截止时间16:00,若下单,物品送达时间为' . date('Y-m-d', strtotime($currentDate . '+2 days'));
}
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
return ['order' => $order, 'cart_list' => $cart_select, 'shopInfo' => $store['near_store'],'alert'=>$alert];
return ['order' => $order, 'cart_list' => $cart_select, 'shopInfo' => $store['near_store'], 'alert' => $alert];
}
/**

View File

@ -82,7 +82,7 @@ class UserLogic extends BaseLogic
}
public static function info($uid)
public static function info($uid,$params=[])
{
$data = User::with(['userShip'])->where('id',$uid)
->field('id,avatar,real_name,nickname,account,mobile,sex,login_ip,now_money,total_recharge_amount,user_ship
@ -123,12 +123,18 @@ class UserLogic extends BaseLogic
$number = UserSign::where('uid',$uid)->where(['status'=>0])->sum('number');
$data['number'] =bcadd($number,0,2);
$data['GetNumber'] =bcadd($GetNumber,0,2);
if(isset($params['store_id']) && $params['store_id']>0){
$share_name=SystemStore::where('id',$params['store_id'])->value('abbreviation');
}else{
if($data['store_id']){
$share_name=SystemStore::where('id',$data['store_id'])->value('abbreviation');
}else{
$share_name=SystemStore::where('id',4)->value('abbreviation');
}
}
$data['share_name']= $share_name.'No.'.preg_replace('/4/','*', $data['id']);
$data['no_code']= 'No.'.preg_replace('/4/','*', $data['id']);
$data['system_store_id']=SystemStoreStaff::where('uid',$uid)->value('store_id');
$data['delivery_service_id']=DeliveryService::where('uid',$uid)->value('id');

View File

@ -11,7 +11,7 @@ class OrderDetail
{
public $warehouse='海吉星仓库';
public $company='投里海';
public $company='投里海';
public $address='泸州龙马潭区海吉星122栋';
public $phone='08302669767';
public $tel='17309099881';