This commit is contained in:
mkm 2024-09-13 20:49:05 +08:00
commit 916a767e0a
130 changed files with 2706 additions and 1247 deletions

View File

@ -339,4 +339,17 @@ class WorkbenchController extends BaseAdminController
return $this->data([], '操作失败', 400); return $this->data([], '操作失败', 400);
} }
} }
/**
* 更新库存和价值
*/
public function stock_product_price()
{
$parmas = $this->request->get();
$res = WarehouseLogic::stockProductPrice($parmas);
if($res){
return $this->success('操作成功,请刷新页面',[],1,1);
}else{
return $this->fail('操作失败');
}
}
} }

View File

@ -46,18 +46,13 @@ class StoreBranchProductController extends BaseAdminController
{ {
$params = (new StoreProductValidate())->post()->goCheck('add'); $params = (new StoreProductValidate())->post()->goCheck('add');
$result = StoreProductLogic::add($params); $result = StoreProductLogic::add($params);
if (true === $result) { return $this->success('添加成功', [], 1, 1);
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(StoreProductLogic::getError());
} }
public function update() public function update()
{ {
$params = $this->request->post(); $params = $this->request->post();
StoreBranchProductLogic::edit($params); StoreBranchProductLogic::edit($params);
if (StoreBranchProductLogic::hasError()) {
return $this->fail(StoreBranchProductLogic::getError());
}
return $this->success('更新成功', [], 1, 1); return $this->success('更新成功', [], 1, 1);
} }
@ -110,9 +105,6 @@ class StoreBranchProductController extends BaseAdminController
{ {
$params = (new StoreProductValidate())->post()->goCheck('delete'); $params = (new StoreProductValidate())->post()->goCheck('delete');
StoreBranchProductLogic::delete($params); StoreBranchProductLogic::delete($params);
if(StoreBranchProductLogic::hasError()){
return $this->fail(StoreBranchProductLogic::getError());
}
return $this->success('删除成功', [], 1, 1); return $this->success('删除成功', [], 1, 1);
} }

View File

@ -7,15 +7,22 @@ use app\admin\controller\BaseAdminController;
use app\admin\lists\store_order\StoreOrderLists; use app\admin\lists\store_order\StoreOrderLists;
use app\admin\lists\store_order\StoreRefundOrderLists; use app\admin\lists\store_order\StoreRefundOrderLists;
use app\admin\logic\store_order\StoreOrderLogic; use app\admin\logic\store_order\StoreOrderLogic;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\admin\validate\store_order\StoreOrderValidate; use app\admin\validate\store_order\StoreOrderValidate;
use app\common\enum\PayEnum; use app\common\enum\PayEnum;
use app\common\logic\PayNotifyLogic; use app\common\logic\PayNotifyLogic;
use app\common\model\delivery_service\DeliveryService; use app\common\model\delivery_service\DeliveryService;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\service\xlsx\OrderDetail; use app\common\service\xlsx\OrderDetail;
use support\exception\BusinessException;
use think\facade\Db;
/** /**
* 订单列表控制器 * 订单列表控制器
@ -117,7 +124,7 @@ class StoreOrderController extends BaseAdminController
*/ */
public function refund() public function refund()
{ {
$params = (new StoreOrderValidate())->goCheck('refund'); $params = $this->request->post();
$detail = StoreOrder::where('order_id', $params['order_id'])->findOrEmpty(); $detail = StoreOrder::where('order_id', $params['order_id'])->findOrEmpty();
if (empty($detail)) { if (empty($detail)) {
return $this->fail('无该订单请检查'); return $this->fail('无该订单请检查');
@ -155,23 +162,94 @@ class StoreOrderController extends BaseAdminController
$id = $this->request->post('id'); $id = $this->request->post('id');
$system_store = $this->request->post('system_store'); $system_store = $this->request->post('system_store');
$xlsx = new OrderDetail(); $xlsx = new OrderDetail();
$order=StoreOrder::where('id',$id)->findOrEmpty(); $order = StoreOrder::where('id', $id)->findOrEmpty();
$time= strtotime('+1 day', $order['pay_time']); $time = strtotime('+1 day', $order['pay_time']);
$order['pay_time']=date('Y-m-d H:i:s',$order['pay_time']); $order['pay_time'] = date('Y-m-d H:i:s', $order['pay_time']);
$order['delivery_time']=date('Y-m-d', $time); $order['delivery_time'] = date('Y-m-d', $time);
$data = StoreOrderCartInfo::where('oid', $id)->select(); $data = StoreOrderCartInfo::where('oid', $id)->select();
foreach ($data as $key => &$value) { foreach ($data as $key => &$value) {
$find=StoreProduct::where('id',$value->product_id)->find(); if(in_array($order['store_id'],[17,18])){
$value->store_name=$find['store_name']??''; $find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->find();
$value->store_info=$find['store_info']??'';
if(!empty($find['unit'])){
$value->unit_name=StoreProductUnit::where('id',$find['unit'])->value('name');
}else{ }else{
$value->unit_name=''; $find = StoreProduct::where('id', $value->product_id)->find();
}
$value->store_name = $find['store_name'] ?? '';
$value->store_info = $find['store_info'] ?? '';
$value->total_price = bcmul($value['price'], $value['cart_num'], 2);
if (!empty($find['unit'])) {
$value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
} else {
$value->unit_name = '';
} }
} }
$file_path = $xlsx->export($data,$system_store,$order); $order['total_price'] = $order['pay_price'];
$file_path = $xlsx->export($data, $system_store, $order);
return $this->success('导出成功', ['url' => $file_path]); return $this->success('导出成功', ['url' => $file_path]);
} }
/**
* 创建出库单
*/
public function createOutboundOrder()
{
$id = $this->request->post('id');
$store_id = $this->request->post('store_id');
$warehouse_id = $this->request->post('warehouse_id');
$delivery_time = $this->request->post('delivery_time');
$mark = $this->request->post('mark');
$find = WarehouseOrder::where('oid',$id)->find();
if($find){
return $this->fail('该订单已创建出库单');
}
$product_arr=StoreOrderCartInfo::where('oid',$id)->field('oid,product_id id,price,total_price,cart_num stock')->select();
if(!$product_arr){
return $this->fail('无商品');
}
Db::startTrans();
try {
$arr = [
'oid' => $id,
'warehouse_id' => $warehouse_id,
'store_id' => $store_id,
'supplier_id' => 0,
'code' => getNewOrderId('PS'),
'admin_id' => $this->adminId,
'financial_pm' => 0,
'batch' => 0,
'mark' => $mark ?? "",
];
$arr['delivery_time'] = strtotime($delivery_time);
$res = WarehouseOrder::create($arr);
foreach ($product_arr as $key => $arr) {
$data = [
'warehouse_id' => $warehouse_id,
'product_id' => $arr['id'],
'store_id' => $store_id,
'financial_pm' => 0,
'batch' => 1,
'nums' => $arr['stock'],
'status' => 1,
'admin_id' => $this->adminId,
];
$storeProduct = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
if ($arr['stock'] == 0) {
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $storeProduct);
} else {
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
$data['purchase'] = $storeProduct['purchase'];
$data['oid'] = $res['id'];
$data['financial_pm'] = 0;
WarehouseProductLogic::add($data);
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
}
}
Db::commit();
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1);
}
} }

View File

@ -54,7 +54,37 @@ class StoreOrderCartInfoController extends BaseAdminController
$res=(new StoreOrderCartInfoLogic())->curve($product_id,$start_time,$end_time); $res=(new StoreOrderCartInfoLogic())->curve($product_id,$start_time,$end_time);
return $this->data($res); return $this->data($res);
} }
/**
* @notes 追加订单商品
* @return \think\response\Json
* @author admin
* @date 2024/05/31 16:02
*/
public function add()
{
$params = $this->request->post();
$result = StoreOrderCartInfoLogic::add($params);
return $this->success('添加成功', [], 1, 1);
}
/**
* @notes 编辑订单商品
* @return \think\response\Json
* @author admin
* @date 2024/05/31 16:02
*/
public function edit()
{
$params = $this->request->post();
$result = StoreOrderCartInfoLogic::edit($params);
return $this->success('编辑成功', [], 1, 1);
}
public function del()
{
$params = $this->request->post();
$result = StoreOrderCartInfoLogic::del($params);
return $this->success('删除成功', [], 1, 1);
}
/** /**
* 导出配送表格 * 导出配送表格
*/ */

View File

@ -44,9 +44,7 @@ class StoreProductController extends BaseAdminController
{ {
$params = (new StoreProductValidate())->post()->goCheck('add'); $params = (new StoreProductValidate())->post()->goCheck('add');
$result = StoreProductLogic::add($params); $result = StoreProductLogic::add($params);
if (true === $result) { return $this->success('添加成功', [], 1, 1);
return $this->success('添加成功', [], 1, 1);
}
} }
@ -62,12 +60,20 @@ class StoreProductController extends BaseAdminController
d($params); d($params);
$result = StoreProductLogic::edit($params); $result = StoreProductLogic::edit($params);
if (true === $result) { return $this->success('编辑成功', [], 1, 1);
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(StoreProductLogic::getError());
} }
/**
* @notes 修改商品状态
* @return \think\response\Json
* @date 2024/05/31 10:53
*/
public function status(){
$params=$this->request->post();
StoreProduct::where('id',$params['id'])->update(['is_show'=>$params['is_show']]);
return $this->success('操作成功',[],1,1);
}
/** /**
* @notes 删除商品列表 * @notes 删除商品列表

View File

@ -40,35 +40,6 @@ class SystemStoreController extends BaseAdminController
{ {
return $this->dataLists(new SystemStoreSourceLists()); return $this->dataLists(new SystemStoreSourceLists());
} }
/**
* @notes 根据商品源获取门店列表
* @return \think\response\Json
* @author admin
* @date 2024/05/31 17:45
*/
public function source_product_update_store()
{
$addList=$this->request->post('addList');
$product_id=$this->request->post('product_id');
if($addList){
foreach ($addList as $key=>$value){
StoreProductLogic::copy($product_id,$value);
if(StoreProductLogic::hasError()){
return $this->fail(StoreProductLogic::getError());
}
}
}
$removeList=$this->request->post('removeList');
if($removeList){
foreach ($removeList as $key=>$value){
StoreProductLogic::store_del($product_id,$value);
if(StoreProductLogic::hasError()){
return $this->fail(StoreProductLogic::getError());
}
}
}
return $this->success('设置成功', [], 1, 1);
}
/** /**
* @notes 添加门店列表 * @notes 添加门店列表

View File

@ -58,7 +58,6 @@ class WarehouseOrderController extends BaseAdminController
if (true === $result) { if (true === $result) {
return $this->success('添加成功', [], 1, 1); return $this->success('添加成功', [], 1, 1);
} }
return $this->fail(WarehouseOrderLogic::getError());
} }
/** /**
* @notes 添加出库单 * @notes 添加出库单
@ -125,7 +124,6 @@ class WarehouseOrderController extends BaseAdminController
Db::commit(); Db::commit();
} catch (\Throwable $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
d($e);
throw new BusinessException($e->getMessage()); throw new BusinessException($e->getMessage());
} }
return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1); return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1);
@ -146,7 +144,6 @@ class WarehouseOrderController extends BaseAdminController
if (true === $result) { if (true === $result) {
return $this->success('编辑成功', [], 1, 1); return $this->success('编辑成功', [], 1, 1);
} }
return $this->fail(WarehouseOrderLogic::getError());
} }
/** /**
@ -174,9 +171,6 @@ class WarehouseOrderController extends BaseAdminController
{ {
$params = (new WarehouseOrderValidate())->post()->goCheck('delete'); $params = (new WarehouseOrderValidate())->post()->goCheck('delete');
WarehouseOrderLogic::delete($params); WarehouseOrderLogic::delete($params);
if(WarehouseOrderLogic::hasError()){
return $this->fail(WarehouseOrderLogic::getError());
}
return $this->success('删除成功', [], 1, 1); return $this->success('删除成功', [], 1, 1);
} }
@ -233,7 +227,11 @@ class WarehouseOrderController extends BaseAdminController
$order['total_num'] = 0; $order['total_num'] = 0;
$total_price=0; $total_price=0;
foreach ($data as $key => &$value) { foreach ($data as $key => &$value) {
$find = StoreProduct::where('id', $value->product_id)->find(); if(in_array($order['store_id'],[17,18])){
$find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->find();
}else{
$find = StoreProduct::where('id', $value->product_id)->find();
}
$value->store_name = $find['store_name'] ?? ''; $value->store_name = $find['store_name'] ?? '';
$value->store_info = $find['store_info'] ?? ''; $value->store_info = $find['store_info'] ?? '';
if($type==2){ if($type==2){

View File

@ -61,12 +61,8 @@ class WarehouseProductController extends BaseAdminController
} }
WarehouseProductLogic::add($data); WarehouseProductLogic::add($data);
} }
return $this->success('添加成功', [], 1, 1);
if (WarehouseProductLogic::hasError()) {
return $this->fail(WarehouseProductLogic::getError());
} else {
return $this->success('添加成功', [], 1, 1);
}
} }
@ -95,11 +91,8 @@ class WarehouseProductController extends BaseAdminController
{ {
$params = (new WarehouseProductValidate())->post()->goCheck('delete'); $params = (new WarehouseProductValidate())->post()->goCheck('delete');
WarehouseProductLogic::delete($params); WarehouseProductLogic::delete($params);
if (WarehouseProductLogic::hasError()) { return $this->success('删除成功', [], 1, 1);
return $this->fail(WarehouseProductLogic::getError());
} else {
return $this->success('删除成功', [], 1, 1);
}
} }
@ -116,6 +109,17 @@ class WarehouseProductController extends BaseAdminController
return $this->data($result); return $this->data($result);
} }
/**
* @notes 结算
* @return \think\response\Json
* @author admin
* @date 2024/07/31 16:55
*/
public function settlement(){
$id=$this->request->post('id');
$result = WarehouseProductLogic::settlement($id);
return $this->success('结算成功', [], 1, 1);
}
/** /**
* 确认操作 * 确认操作
*/ */

View File

@ -80,21 +80,46 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
$list = StoreProduct::where($this->searchWhere) $list = StoreProduct::where($this->searchWhere)
->alias('p') // 为 StoreProduct 表设置别名 ->alias('p') // 为 StoreProduct 表设置别名
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->field('p.id, p.store_name, p.image,p.stock as total_stock, ->field('p.id, p.store_name, p.image,p.stock as total_stock,p.unit,p.total_price,
(SELECT SUM(c.cart_num) FROM `la_store_order_cart_info` c WHERE c.product_id=p.id AND c.is_pay=1 AND c.delete_time IS NULL) AS sales, (SELECT SUM(c.cart_num) FROM `la_store_order_cart_info` c WHERE c.product_id=p.id AND c.is_pay=1 AND c.delete_time IS NULL) AS sales,
(SELECT SUM(b.stock) FROM `la_store_branch_product` b WHERE b.product_id=p.id AND b.delete_time IS NULL) AS store_stock, (SELECT SUM(b.stock) FROM `la_store_branch_product` b WHERE b.product_id=p.id AND b.delete_time IS NULL) AS store_stock,
(SELECT SUM(w.nums) FROM `la_warehouse_product_storege` w WHERE w.product_id=p.id AND w.delete_time IS NULL) AS warehouse_stock, (SELECT SUM(w.nums) FROM `la_warehouse_product_storege` w WHERE w.product_id=p.id AND w.delete_time IS NULL) AS warehouse_stock,
(SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.delete_time IS NULL) AS total_purchase, (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.financial_pm=1 AND wp.delete_time IS NULL) AS total_purchase,
(SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=1 AND wp.delete_time IS NULL) AS total_completed_amount, (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.financial_pm=1 AND wp.is_pay=1 AND wp.delete_time IS NULL) AS total_completed_amount,
(SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=0 AND wp.delete_time IS NULL) AS total_outstanding_amount') (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.financial_pm=1 AND wp.is_pay=0 AND wp.delete_time IS NULL) AS total_outstanding_amount')
->order($this->sortOrder) ->order($this->sortOrder)
->select() ->select()
->each(function ($item) { ->each(function ($item) {
// 计算总库存 // 计算总库存
$item->total_completed_amount=$item->total_completed_amount??0; $unit_name=StoreProductUnit::where('id',$item->unit)->value('name');
$item->warehouse_stock=$item->warehouse_stock??0; if($item->total_stock){
$item->total_outstanding_amount=$item->total_outstanding_amount??0; $item->total_stock=bcadd($item->total_stock??0,$item->warehouse_stock??0,2).'|'.$unit_name;
$item->total_purchase=$item->total_purchase??0; }else{
$item->total_stock='';
}
$item->sales=$item->sales.'|'.$unit_name;
$item->store_stock=$item->store_stock.'|'.$unit_name;
$item->warehouse_stock=$item->warehouse_stock.'|'.$unit_name;
if($item->total_completed_amount){
$item->total_completed_amount=$item->total_completed_amount.'元';
}else{
$item->total_completed_amount='0元';
}
if($item->total_outstanding_amount){
$item->total_outstanding_amount=$item->total_outstanding_amount.'元';
}else{
$item->total_outstanding_amount='0元';
}
if($item->total_purchase){
$item->total_purchase=$item->total_purchase.'元';
}else{
$item->total_purchase='0元';
}
if($item->total_price){
$item->total_price=$item->total_price.'元';
}else{
$item->total_price='0元';
}
}) })
->toArray(); ->toArray();
return $list; return $list;

View File

@ -12,6 +12,7 @@ use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\lists\ListsExcelInterface; use app\common\lists\ListsExcelInterface;
use app\common\lists\ListsSortInterface; use app\common\lists\ListsSortInterface;
use app\common\model\store_product\StoreProduct;
/** /**
* 门店商品辅助表 * 门店商品辅助表
@ -65,6 +66,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
public function lists(): array public function lists(): array
{ {
$class_all = $this->request->get('class_all'); $class_all = $this->request->get('class_all');
$export=$this->request->get('export');
$where = []; $where = [];
if ($class_all) { if ($class_all) {
$arr = Cate::where('pid', $class_all)->column('id'); $arr = Cate::where('pid', $class_all)->column('id');
@ -81,17 +83,20 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
$this->searchWhere[] = $where; $this->searchWhere[] = $where;
} }
return StoreBranchProduct::where($this->searchWhere) return StoreBranchProduct::where($this->searchWhere)
->field(['id', 'store_id', 'product_id', 'image', 'store_name', 'store_info', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'purchase', 'status', 'batch', 'vip_price','bar_code', 'manufacturer_information']) ->field(['id', 'store_id', 'product_id', 'image', 'store_name', 'store_info', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'purchase', 'status', 'batch', 'vip_price','bar_code', 'manufacturer_information','total_price'])
->when(!empty($this->adminInfo['store_id']), function ($query) { ->when(!empty($this->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->adminInfo['store_id']); $query->where('store_id', $this->adminInfo['store_id']);
}) })
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order($this->sortOrder) ->order($this->sortOrder)
->select() ->select()
->each(function ($item) { ->each(function ($item) use($export) {
$item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name'); $item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name');
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
$item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
if($export==2){
$item['total_price'] = bcmul($item['purchase'],$item['stock'],2);
}
return $item; return $item;
}) })
->toArray(); ->toArray();
@ -138,6 +143,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
public function setExcelFields(): array public function setExcelFields(): array
{ {
$data = [ $data = [
'product_id' => '商品ID',
'store_name' => '商品名称', 'store_name' => '商品名称',
'store_info' => '规格', 'store_info' => '规格',
'unit_name' => '单位', 'unit_name' => '单位',
@ -149,6 +155,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
'vip_price' => '会员价', 'vip_price' => '会员价',
'price' => '零售价', 'price' => '零售价',
'bar_code' => '条码', 'bar_code' => '条码',
'total_price' => '价值',
]; ];
return $data; return $data;
} }

View File

@ -11,13 +11,14 @@ use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\user\User; use app\common\model\user\User;
use app\common\lists\ListsExcelInterface;
/** /**
* 订单列表列表 * 订单列表列表
* Class StoreOrderLists * Class StoreOrderLists
* @package app\admin\listsstore_order * @package app\admin\listsstore_order
*/ */
class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
{ {
@ -30,7 +31,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['order_id','store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff','is_merge'], '=' => ['order_id','store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff','is_merge','uid'],
'between_time' => 'create_time' 'between_time' => 'create_time'
]; ];
} }
@ -62,7 +63,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
$query->whereIn('status', $status); $query->whereIn('status', $status);
} }
}) })
->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price','total_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status','create_time','delivery_name','delivery_id']) ->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price','total_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status','create_time','delivery_name','delivery_id','refund_price'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function ($item) { ->select()->each(function ($item) {
@ -119,4 +120,38 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
}) })
->count(); ->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 = [
'id' => 'ID',
'order_id'=>'订单号',
'store_name'=>'门店',
'nickname' => '用户',
'total_price' => '总金额',
'pay_price' => '实际支付',
'status_name' => '状态',
'refund_price' => '退款金额',
'pay_time' => '支付时间',
];
return $data;
}
} }

View File

@ -13,6 +13,8 @@ use app\common\lists\ListsExcelInterface;
use app\common\model\store_category\StoreCategory; use app\common\model\store_category\StoreCategory;
use app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
/** /**
* 订单购物详情列表 * 订单购物详情列表
@ -49,21 +51,41 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
public function lists(): array public function lists(): array
{ {
return StoreOrderCartInfo::where($this->searchWhere) return StoreOrderCartInfo::where($this->searchWhere)
->field('oid,cart_info,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength) ->field('id,oid,uid,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength)
->select()->each(function ($item) { ->select()->each(function ($item) {
$find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find(); $find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find();
if($find){ if($find){
if($item['uid']>0){
$user=User::where('id',$item['uid'])->field('real_name,mobile')->find();
if($user){
if($user['real_name']!=''){
$item['nickname']=$user['real_name'];
}else{
$item['nickname']=$user['mobile'];
}
}else{
$item['nickname']='无';
}
}else{
$item['nickname']='无';
}
$item['image']=$find['image'];//商品图片 $item['image']=$find['image'];//商品图片
$item['system_store']=SystemStore::where('id',$item['store_id'])->value('name')??"";
$item['store_name']=$find['store_name'];//商品名称 $item['store_name']=$find['store_name'];//商品名称
$item['store_info']=$find['store_info'];//商品规格 $item['store_info']=$find['store_info'];//商品规格
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??""; $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??"";
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name')??""; $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name')??"";
$item['pay_price'] =$item['total_price'];
$item['cart_info'] = $item->toArray()??[];
}else{ }else{
$item['image']='';//商品图片 $item['image']='';//商品图片
$item['unit_name']='';//商品图片 $item['unit_name']='';//商品图片
$item['cate_name']='';//商品图片 $item['cate_name']='';//商品图片
$item['store_name']='';//商品名称 $item['store_name']='';//商品名称
$item['store_info']='';//商品规格-(数据库叫商品简介) $item['store_info']='';//商品规格-(数据库叫商品简介)
$item['nickname']='';
$item['system_store']='';
$item['cart_info']=[];
} }
return $item; //返回处理后的数据。 return $item; //返回处理后的数据。
}) })
@ -108,12 +130,15 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
{ {
$data=[ $data=[
'store_name' => '商品名称', 'store_name' => '商品名称',
'system_store' => '门店',
'nickname' => '用户',
'store_info' => '规格', 'store_info' => '规格',
'unit_name' => '单位', 'unit_name' => '单位',
'cate_name' => '分类', 'cate_name' => '分类',
'cart_num' => '数量', 'cart_num' => '数量',
'price' => '单价', 'price' => '单价',
'total_price' => '总价', 'total_price' => '总价',
'create_time' => '时间',
]; ];
return $data; return $data;
} }

View File

@ -63,31 +63,36 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
if ($this->request->get('start_time') == '') { if ($this->request->get('start_time') == '') {
$this->searchWhere[] = ['create_time', 'between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]]; $this->searchWhere[] = ['create_time', 'between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]];
} }
$this->searchWhere[]=['is_pay','=',1]; $is_group=$this->request->get('is_group');
$this->searchWhere[]=['status','>=',0]; $this->searchWhere[] = ['is_pay', '=', 1];
$this->searchWhere[] = ['status', '>=', 0];
$query = StoreOrderCartInfo::where($this->searchWhere); $query = StoreOrderCartInfo::where($this->searchWhere);
if ($this->request->get('is_group') == 1) { if ($is_group == 1) {
$query->field('store_id,product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group(['store_id', 'product_id']); $query->field('store_id,product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group(['store_id', 'product_id']);
} else { } else {
$query->field('store_id,product_id,price,total_price,cart_num'); $query->field('store_id,product_id,price,total_price,cart_num,create_time');
} }
return $query->limit($this->limitOffset, $this->limitLength) return $query->limit($this->limitOffset, $this->limitLength)
->select()->each(function ($item) { ->select()->each(function ($item) use($is_group){
$find = StoreProduct::where('id', $item['product_id'])->field('image,unit,cate_id,store_name,store_info')->find(); $find = StoreProduct::where('id', $item['product_id'])->field('image,unit,cate_id,store_name,store_info')->find();
if ($find) { if ($find) {
$item['image'] = $find['image']; //商品图片 $item['image'] = $find['image']; //商品图片
$item['store_name'] = $find['store_name']; //商品名称 if($is_group==1){
$item['store_name'] = $find['store_name'].'-'.$item['create_time']; //商品名称
}else{
$item['store_name'] = $find['store_name']; //商品名称
}
$item['store_info'] = $find['store_info']; //商品规格 $item['store_info'] = $find['store_info']; //商品规格
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??''; $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name') ?? '';
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name')??''; $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name') ?? '';
$item['system_store'] = SystemStore::where('id', $item['store_id'])->value('name')??''; $item['system_store'] = SystemStore::where('id', $item['store_id'])->value('name') ?? '';
}else{ } else {
$item['image']='';//商品图片 $item['image'] = ''; //商品图片
$item['store_name']='';//商品名称 $item['store_name'] = ''; //商品名称
$item['store_info']='';//商品规格-(数据库叫商品简介) $item['store_info'] = ''; //商品规格-(数据库叫商品简介)
$item['unit_name']='';// $item['unit_name'] = ''; //
$item['cate_name']='';// $item['cate_name'] = ''; //
$item['system_store']='';// $item['system_store'] = ''; //
} }
return $item; //返回处理后的数据。 return $item; //返回处理后的数据。
}) })
@ -130,16 +135,31 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
*/ */
public function setExcelFields(): array public function setExcelFields(): array
{ {
$data = [ if ($this->request->get('is_group') == 1) {
'system_store' => '门店', $data = [
'store_name' => '商品名称', 'system_store' => '门店',
'store_info' => '规格', 'store_name' => '商品名称',
'unit_name' => '单位', 'store_info' => '规格',
'cate_name' => '分类', 'unit_name' => '单位',
'cart_num' => '数量', 'cate_name' => '分类',
'price' => '单价', 'cart_num' => '数量',
'total_price' => '总价', 'price' => '单价',
]; 'total_price' => '总价',
];
} else {
$data = [
'system_store' => '门店',
'store_name' => '商品名称',
'store_info' => '规格',
'unit_name' => '单位',
'cate_name' => '分类',
'cart_num' => '数量',
'price' => '单价',
'total_price' => '总价',
'create_time' => '时间',
];
}
return $data; return $data;
} }
} }

View File

@ -62,15 +62,50 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
} }
} }
return StoreProduct::where($this->searchWhere) return StoreProduct::where($this->searchWhere)
->field(['id', 'image', 'store_name', 'swap', 'product_type', 'cate_id', 'batch', 'price', 'vip_price', 'sales', 'stock', 'is_show', 'unit', 'cost', 'rose', 'purchase', 'bar_code', 'manufacturer_information']) ->field(['id', 'image', 'store_info', 'store_name', 'top_cate_id', 'two_cate_id', 'swap', 'product_type', 'cate_id', 'batch', 'price', 'vip_price', 'sales', 'stock', 'is_show', 'unit', 'cost', 'rose', 'purchase', 'bar_code', 'manufacturer_information'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function ($item) { ->select()->each(function ($item) {
$item['bar_code_two'] = '';
if (in_array($item['unit'], [2, 21])) {
$item['bar_code_two'] = $item['bar_code'];
if ($item['bar_code'] == 0) {
$item['bar_code_two'] = '';
}
$item['bar_code'] = '';
$item['unit_names'] = '称重商品';
} else {
if (strlen($item['bar_code']) < 10) {
$item['bar_code_two'] = $item['bar_code'];
if ($item['bar_code'] == 0) {
$item['bar_code_two'] = '';
}
$item['bar_code'] = '';
}
$item['unit_names'] = '标准商品';
}
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
$nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums'); $nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
$stock = StoreBranchProduct::where('store_id', '<>', '4')->where('product_id', $item['id'])->sum('stock'); $stock = StoreBranchProduct::where('store_id', '<>', '4')->where('product_id', $item['id'])->sum('stock');
$item['stock'] = bcadd($nums, $stock); $item['stock'] = bcadd($nums, $stock);
$item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); $cate_name = '';
$category_top = StoreCategory::where('id', $item['top_cate_id'])->value('name');
if ($category_top != '') {
$cate_name = '/' . $category_top;
}
if (!$category_top) {
$category_two = StoreCategory::where('id', $item['two_cate_id'])->value('name');
if ($category_two != '') {
$cate_name = $cate_name . '/' . $category_two;
}
}
$category_three = StoreCategory::where('id', $item['cate_id'])->value('name');
if ($category_three) {
$cate_name = $cate_name . '/' . $category_three;
}
$item['cate_name'] = $cate_name;
// $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
return $item; return $item;
})?->toArray(); })?->toArray();
} }
@ -84,8 +119,8 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
*/ */
public function count(): int public function count(): int
{ {
$export=$this->request->get('export'); $export = $this->request->get('export');
if($export==1){ if ($export == 1) {
$class_all = $this->request->get('class_all'); $class_all = $this->request->get('class_all');
if ($class_all) { if ($class_all) {
//查3级别的 //查3级别的
@ -122,14 +157,18 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
public function setExcelFields(): array public function setExcelFields(): array
{ {
$data = [ $data = [
'id' => '商品id',
'unit_names' => '计价方式',
'store_name' => '商品名称', 'store_name' => '商品名称',
'cate_name'=>'分类', 'cate_name' => '分类',
'unit_name'=>'单位', 'unit_name' => '单位',
'store_info' => '规格',
'stock' => '库存', 'stock' => '库存',
'purchase' => '采购价', 'purchase' => '采购价',
'cost' => '商户', 'cost' => '商户',
'price' => '零售', 'price' => '零售',
'bar_code' => '条码', 'bar_code' => '条码',
'bar_code_two' => '自编码',
]; ];
return $data; return $data;
} }

View File

@ -6,7 +6,7 @@ namespace app\admin\lists\supplier;
use app\admin\lists\BaseAdminDataLists; use app\admin\lists\BaseAdminDataLists;
use app\common\model\supplier\Supplier; use app\common\model\supplier\Supplier;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\warehouse_product\WarehouseProduct;
/** /**
* 供应链列表 * 供应链列表
@ -47,7 +47,10 @@ class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface
->field(['id', 'category_id', 'mer_name', 'phone', 'settle_cycle', 'address', 'mark']) ->field(['id', 'category_id', 'mer_name', 'phone', 'settle_cycle', 'address', 'mark'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select() ->select()->each(function ($item) {
$item->total_completed_amount=WarehouseProduct::where('supplier_id',$item['id'])->where('financial_pm',1)->where('is_pay',1)->sum('total_price');
$item->total_outstanding_amount=WarehouseProduct::where('supplier_id',$item['id'])->where('financial_pm',1)->where('is_pay',0)->sum('total_price');
})
->toArray(); ->toArray();
} }

View File

@ -29,6 +29,7 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface,ListsS
'=' => ['store_id','user_ship','is_disable'], '=' => ['store_id','user_ship','is_disable'],
'%like%' => ['account','mobile'], '%like%' => ['account','mobile'],
'%pipe_like%' => ['nickname'=>'nickname|real_name'], '%pipe_like%' => ['nickname'=>'nickname|real_name'],
'between_time' => 'vip_time'
]; ];
} }

View File

@ -7,13 +7,14 @@ use app\admin\lists\BaseAdminDataLists;
use app\common\model\user_recharge\UserRecharge; use app\common\model\user_recharge\UserRecharge;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\user\User; use app\common\model\user\User;
use app\common\lists\ListsExcelInterface;
/** /**
* 充值记录列表 * 充值记录列表
* Class UserRechargeLists * Class UserRechargeLists
* @package app\admin\listsuser_recharge * @package app\admin\listsuser_recharge
*/ */
class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterface class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
{ {
@ -88,4 +89,34 @@ class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterfa
return UserRecharge::where($this->searchWhere)->count(); return UserRecharge::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 = [
'id' => 'ID',
'order_id'=>'订单号',
'nickname' => '用户',
'price' => '实际支付',
'paid_name' => '状态',
'pay_time' => '支付时间',
];
return $data;
}
} }

View File

@ -29,7 +29,8 @@ class WarehouseOrderLists extends BaseAdminDataLists implements ListsSearchInter
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'='=>['financial_pm'] '='=>['financial_pm','supplier_id','warehouse_id','store_id'],
'between_time' => 'create_time'
]; ];
} }

View File

@ -33,7 +33,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['warehouse_id', 'financial_pm', 'store_id','oid','supplier_id'], '=' => ['warehouse_id', 'financial_pm', 'store_id','oid','supplier_id','is_pay'],
'between_time' => 'create_time' 'between_time' => 'create_time'
]; ];
} }
@ -71,7 +71,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
} }
} }
return WarehouseProduct::where($this->searchWhere) return WarehouseProduct::where($this->searchWhere)
->field(['id', 'oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time']) ->field(['id', 'oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function ($item) { ->select()->each(function ($item) {
@ -106,6 +106,8 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
} }
} else { } else {
$item->store_name = ''; $item->store_name = '';
$item->image = '';
$item->price = '';
} }
if ($item->warehouse_id) { if ($item->warehouse_id) {
$item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name'); $item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name');
@ -114,6 +116,8 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
} }
if ($item->supplier_id) { if ($item->supplier_id) {
$item->supplier_name = Supplier::where('id', $item->supplier_id)->value('mer_name'); $item->supplier_name = Supplier::where('id', $item->supplier_id)->value('mer_name');
}else{
$item->supplier_name = '';
} }
$item->expiration_date = $item->expiration_date ? date('Y-m-d', $item->expiration_date) : ''; $item->expiration_date = $item->expiration_date ? date('Y-m-d', $item->expiration_date) : '';
$item->manufacture = $item->manufacture ? date('Y-m-d', $item->manufacture) : ''; $item->manufacture = $item->manufacture ? date('Y-m-d', $item->manufacture) : '';

View File

@ -18,6 +18,7 @@ use app\common\logic\BaseLogic;
use app\common\model\Config; use app\common\model\Config;
use app\common\model\dict\DictData; use app\common\model\dict\DictData;
use app\common\service\{FileService, ConfigService}; use app\common\service\{FileService, ConfigService};
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
/** /**
@ -46,10 +47,9 @@ class ConfigLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -73,10 +73,9 @@ class ConfigLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\app_update;
use app\common\model\app_update\AppUpdate; use app\common\model\app_update\AppUpdate;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -40,10 +41,9 @@ class AppUpdateLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -71,10 +71,9 @@ class AppUpdateLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -24,6 +24,7 @@ use app\common\model\auth\AdminRole;
use app\common\model\auth\AdminSession; use app\common\model\auth\AdminSession;
use app\common\cache\AdminTokenCache; use app\common\cache\AdminTokenCache;
use app\common\service\FileService; use app\common\service\FileService;
use support\exception\BusinessException;
use Webman\Config; use Webman\Config;
use think\facade\Db; use think\facade\Db;
@ -70,10 +71,9 @@ class AdminLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -138,10 +138,9 @@ class AdminLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -177,10 +176,9 @@ class AdminLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -20,6 +20,7 @@ use app\common\{
logic\BaseLogic, logic\BaseLogic,
model\auth\SystemRoleMenu model\auth\SystemRoleMenu
}; };
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -66,8 +67,7 @@ class RoleLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::$error = $e->getMessage(); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -110,8 +110,7 @@ class RoleLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::$error = $e->getMessage(); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\delivery_service;
use app\common\model\delivery_service\DeliveryService; use app\common\model\delivery_service\DeliveryService;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -37,10 +38,9 @@ class DeliveryServiceLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -65,10 +65,9 @@ class DeliveryServiceLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -17,7 +17,7 @@ namespace app\admin\logic\dept;
use app\common\enum\YesNoEnum; use app\common\enum\YesNoEnum;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\dept\Dept; use app\common\model\dept\Dept;
use support\exception\BusinessException;
/** /**
* 部门管理逻辑 * 部门管理逻辑
@ -147,9 +147,8 @@ class DeptLogic extends BaseLogic
'sort' => $params['sort'] ?? 0 'sort' => $params['sort'] ?? 0
]); ]);
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -17,7 +17,7 @@ namespace app\admin\logic\dept;
use app\common\enum\YesNoEnum; use app\common\enum\YesNoEnum;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\dept\Jobs; use app\common\model\dept\Jobs;
use support\exception\BusinessException;
/** /**
* 岗位管理逻辑 * 岗位管理逻辑
@ -65,9 +65,8 @@ class JobsLogic extends BaseLogic
'remark' => $params['remark'] ?? '', 'remark' => $params['remark'] ?? '',
]); ]);
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -6,6 +6,7 @@ namespace app\admin\logic\financial_transfers;
use app\common\model\financial_transfers\FinancialTransfers; use app\common\model\financial_transfers\FinancialTransfers;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow; use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -43,10 +44,9 @@ class FinancialTransfersLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -76,10 +76,9 @@ class FinancialTransfersLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -123,10 +122,9 @@ class FinancialTransfersLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -138,7 +136,7 @@ class FinancialTransfersLogic extends BaseLogic
$date = date('Y-m-d', $time); //获取一个月前的日期 $date = date('Y-m-d', $time); //获取一个月前的日期
$receivable = StoreCashFinanceFlow::whereMonth('create_time', $date)->where('status', 0)->sum('receivable'); $receivable = StoreCashFinanceFlow::whereMonth('create_time', $date)->where('status', 0)->sum('receivable');
if($receivable==0){ if($receivable==0){
self::setError('暂无法确认,还有未收取的现金'); throw new BusinessException('暂无法确认,还有未收取的现金');
} }
Db::startTrans(); Db::startTrans();
try { try {
@ -149,10 +147,9 @@ class FinancialTransfersLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
} }

View File

@ -7,6 +7,7 @@ use app\common\model\inventory_transfer\InventoryTransfer;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\warehouse_product_storege\WarehouseProductStorege; use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -35,8 +36,7 @@ class InventoryTransferLogic extends BaseLogic
if($params['one_type']==1){ if($params['one_type']==1){
$stock = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['one_id'])->value('stock'); $stock = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['one_id'])->value('stock');
if ($stock < $params['nums']) { if ($stock < $params['nums']) {
self::setError('调拨数量不能大于当前门店库存'); throw new BusinessException('调拨数量不能大于当前门店库存');
return false;
} }
if($params['two_type']==1){ if($params['two_type']==1){
$stock_two = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->value('stock'); $stock_two = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->value('stock');
@ -51,8 +51,7 @@ class InventoryTransferLogic extends BaseLogic
}elseif($params['one_type']==2){ }elseif($params['one_type']==2){
$stock = WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['one_id'])->value('nums'); $stock = WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['one_id'])->value('nums');
if ($stock < $params['nums']) { if ($stock < $params['nums']) {
self::setError('调拨数量不能大于当前仓库库存'); throw new BusinessException('调拨数量不能大于当前仓库库存');
return false;
} }
if($params['two_type']==1){ if($params['two_type']==1){
$stock_two = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->value('stock'); $stock_two = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->value('stock');
@ -65,8 +64,7 @@ class InventoryTransferLogic extends BaseLogic
$two_before_nums = $stock_two; $two_before_nums = $stock_two;
$two_after_nums = bcadd($stock_two, $params['nums']); $two_after_nums = bcadd($stock_two, $params['nums']);
}else{ }else{
self::setError('调拨类型错误'); throw new BusinessException('调拨类型错误');
return false;
} }
Db::startTrans(); Db::startTrans();
@ -97,8 +95,7 @@ class InventoryTransferLogic extends BaseLogic
return true; return true;
} catch (\Throwable $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -127,8 +124,7 @@ class InventoryTransferLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -11,6 +11,7 @@ use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -181,8 +182,7 @@ class PurchaseOrderLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -231,8 +231,7 @@ class PurchaseOrderLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -6,6 +6,7 @@ use app\common\logic\BaseLogic;
use app\common\model\purchase_order_info\PurchaseOrderInfo; use app\common\model\purchase_order_info\PurchaseOrderInfo;
use app\common\model\purchase_product_offer\PurchaseProductOffer; use app\common\model\purchase_product_offer\PurchaseProductOffer;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
class PurchaseOrderInfoLogic extends BaseLogic class PurchaseOrderInfoLogic extends BaseLogic
@ -37,8 +38,7 @@ class PurchaseOrderInfoLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
} }

View File

@ -6,6 +6,7 @@ namespace app\admin\logic\purchase_product_offer;
use app\common\model\purchase_product_offer\PurchaseProductOffer; use app\common\model\purchase_product_offer\PurchaseProductOffer;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\delivery_service\DeliveryService; use app\common\model\delivery_service\DeliveryService;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -53,8 +54,7 @@ class PurchaseProductOfferLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -94,8 +94,7 @@ class PurchaseProductOfferLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -106,8 +105,7 @@ class PurchaseProductOfferLogic extends BaseLogic
{ {
if($params['is_buyer']==1){ if($params['is_buyer']==1){
if($params['buyer_id']==''){ if($params['buyer_id']==''){
self::setError('采购人不能为空'); throw new BusinessException('采购人不能为空');
return false;
} }
$data['buyer_id']=$params['buyer_id']; $data['buyer_id']=$params['buyer_id'];
$data['buyer_nums']=$params['buyer_nums']; $data['buyer_nums']=$params['buyer_nums'];
@ -120,8 +118,7 @@ class PurchaseProductOfferLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
/** /**

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\setting;
use app\common\model\setting\Category; use app\common\model\setting\Category;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -43,8 +44,7 @@ class CategoryLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -75,8 +75,7 @@ class CategoryLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -4,6 +4,7 @@ namespace app\admin\logic\statistic;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
@ -48,12 +49,33 @@ class WarehouseLogic extends BaseLogic
'value' => [], 'value' => [],
'type' => 1, 'type' => 1,
]; ];
$toreProduct = StoreProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find(); $pay_price=StoreOrder::where('paid',1)->where('refund_status',0)->sum('pay_price');
// $refund_price=StoreOrder::where('paid',1)->sum('refund_price');
$topData[] = [
'title' => '交易金额',
'desc' => '平台发生交易的金额',
'total_money' =>$pay_price,
'value' => [],
'type' => 1,
];
$number=StoreFinanceFlow::where('financial_type',3)->where('financial_pm',1)->sum('number');
$topData[] = [
'title' => '获得利润',
'desc' => '平台订单产生的手续费',
'total_money' =>$number,
'value' => [],
'type' => 1,
];
// $toreProduct = StoreProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find();
$warehouseProductStorege = WarehouseProductStorege::where('nums', '>', 0)->field('sum(nums) as nums,sum(total_price) as total_price')->find();
$storeBranchProduct = StoreBranchProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find();
$topData[] = [ $topData[] = [
'title' => '总商品库存', 'title' => '总商品库存',
'desc' => '平台统计商品总库存、含门店仓库', 'desc' => '平台统计商品总库存、含门店仓库',
'total_money' => $toreProduct['stock'], 'total_money' => bcadd($warehouseProductStorege['nums'], $storeBranchProduct['stock'], 2),
'cash_title' => $toreProduct['total_price'], 'cash_title' => bcadd($warehouseProductStorege['total_price'], $storeBranchProduct['total_price'], 2),
'value' => [], 'value' => [],
'type' => 1, 'type' => 1,
]; ];
@ -84,7 +106,6 @@ class WarehouseLogic extends BaseLogic
'value' => [], 'value' => [],
'type' => 1, 'type' => 1,
]; ];
$storeBranchProduct = StoreBranchProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find();
$topData[] = [ $topData[] = [
'title' => '总门店库存', 'title' => '总门店库存',
'desc' => '平台统计门店库存', 'desc' => '平台统计门店库存',
@ -190,14 +211,14 @@ class WarehouseLogic extends BaseLogic
$list = StoreProduct::where('stock', '<', 0)->page($parmas['page_no'], 15)->select()->toArray(); $list = StoreProduct::where('stock', '<', 0)->page($parmas['page_no'], 15)->select()->toArray();
$count = StoreProduct::where('stock', '<', 0)->count(); $count = StoreProduct::where('stock', '<', 0)->count();
} elseif ($parmas['type'] == 2) { } elseif ($parmas['type'] == 2) {
$where[]=['stock','<',0]; $where[] = ['stock', '<', 0];
if(isset($parmas['store_id']) && $parmas['store_id'] > 0){ if (isset($parmas['store_id']) && $parmas['store_id'] > 0) {
$where[]=['store_id','=',$parmas['store_id']]; $where[] = ['store_id', '=', $parmas['store_id']];
} }
$store_arr=getenv('NO_STORE_STATISTICS'); $store_arr = getenv('NO_STORE_STATISTICS');
if($store_arr){ if ($store_arr) {
$store_arr=explode(',',$store_arr); $store_arr = explode(',', $store_arr);
$where[]=['store_id','not in',$store_arr]; $where[] = ['store_id', 'not in', $store_arr];
} }
$list = StoreBranchProduct::where($where)->page($parmas['page_no'], 15)->select() $list = StoreBranchProduct::where($where)->page($parmas['page_no'], 15)->select()
->each(function ($item) { ->each(function ($item) {
@ -217,19 +238,55 @@ class WarehouseLogic extends BaseLogic
$count = WarehouseProductStorege::where('nums', '<', 0)->count(); $count = WarehouseProductStorege::where('nums', '<', 0)->count();
} }
return ['lists' => $list, 'count' => $count]; return ['lists' => $list, 'count' => $count];
} }
/** /**
* 负库存更新归0 * 负库存更新归0
*/ */
public static function updateNegativeZero($parmas) public static function updateNegativeZero($parmas)
{ {
if ($parmas['type'] == 1) { if ($parmas['type'] == 1) {
$res = StoreProduct::where('id',$parmas['id'])->update(['stock'=>0]); $res = StoreProduct::where('id', $parmas['id'])->update(['stock' => 0]);
} elseif ($parmas['type'] == 2) { } elseif ($parmas['type'] == 2) {
$res=StoreBranchProduct::where('id',$parmas['id'])->update(['stock'=>0]); $res = StoreBranchProduct::where('id', $parmas['id'])->update(['stock' => 0]);
} elseif ($parmas['type'] == 3) { } elseif ($parmas['type'] == 3) {
$res = WarehouseProductStorege::where('id',$parmas['id'])->update(['nums'=>0]); $res = WarehouseProductStorege::where('id', $parmas['id'])->update(['nums' => 0]);
} }
return $res; return $res;
} }
public static function stockProductPrice($parmas)
{
$arr1 = WarehouseProductStorege::where('nums', '>', 0)->select();
foreach ($arr1 as $k => $v) {
$find = StoreProduct::where('id', $v['product_id'])->find();
if ($find && $find['price'] > 0) {
$total_price = bcmul($find['price'], $v['nums'], 2);
$price = $find['price'];
} else {
$total_price = 0;
$price = 0;
}
WarehouseProductStorege::where('id', $v['id'])->update(['price' => $price, 'total_price' => $total_price]);
}
$arr2 = StoreBranchProduct::where('stock', '>', 0)->select();
foreach ($arr2 as $k => $v) {
if ($v['price'] > 0) {
$total_price = bcmul($v['price'], $v['stock'], 2);
} else {
$total_price = 0;
}
StoreBranchProduct::where('id', $v['id'])->update(['total_price' => $total_price]);
}
$arr3 = StoreProduct::where('stock', '>=', 0)->select();
foreach ($arr3 as $k => $v) {
$stock = StoreBranchProduct::where('product_id', $v['id'])->where('stock', '>', 0)->sum('stock');
$nums = WarehouseProductStorege::where('nums', '>', 0)->where('product_id', $v['id'])->sum('nums');
$stock2 = bcadd($stock, $nums, 2);
bcmul($v['purchase'], $stock2, 2);
StoreProduct::where('id', $v['id'])->update(['stock' => $stock2, 'total_price' => $v]);
}
return true;
}
} }

View File

@ -36,8 +36,7 @@ class StoreBranchProductLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -52,8 +51,7 @@ class StoreBranchProductLogic extends BaseLogic
{ {
$StoreProduct = StoreBranchProduct::where('id', $params['id'])->find(); $StoreProduct = StoreBranchProduct::where('id', $params['id'])->find();
if ($params['status'] == 1 && $StoreProduct['price'] == 0) { if ($params['status'] == 1 && $StoreProduct['price'] == 0) {
self::setError('商品价格不能为0,无法上架'); throw new BusinessException('商品价格不能为0,无法上架');
return false;
} }
Db::startTrans(); Db::startTrans();
try { try {
@ -67,10 +65,9 @@ class StoreBranchProductLogic extends BaseLogic
StoreBranchProduct::where('id', $params['id'])->update($data); StoreBranchProduct::where('id', $params['id'])->update($data);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException('商品编辑失败:',$e->getMessage());
return false;
} }
} }
/** /**
@ -84,19 +81,22 @@ class StoreBranchProductLogic extends BaseLogic
{ {
Db::startTrans(); Db::startTrans();
try { try {
$find = StoreProduct::where('id', $params['product_id'])->find(); $find = StoreProduct::where('id', $params['product_id'])->find()->toArray();
$storeBranchProduct = StoreBranchProduct::where('id', $params['id'])->find(); $storeBranchProduct = StoreBranchProduct::where('id', $params['id'])->find()->toArray();
if ($type == 1) { if ($type == 1) {
$stock = bcadd($find['stock'], $params['nums'], 2); $stock = bcadd($find['stock'], $params['nums'], 2);
$branchStock = bcadd($storeBranchProduct['stock'], $params['nums'], 2); $branchStock = bcadd($storeBranchProduct['stock'], $params['nums'], 2);
StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)]); StoreBranchProduct::update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)],['id'=> $params['id']]);
StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)]); StoreProduct::update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)],['id'=> $params['product_id']]);
} else { } else {
$branchStock = bcsub($storeBranchProduct['stock'], $params['nums'], 2); $branchStock = bcsub($storeBranchProduct['stock'], $params['nums'], 2);
$stock = bcsub($find['stock'], $params['nums'], 2); $stock = bcsub($find['stock'], $params['nums'], 2);
StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)]);
StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)]); StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)],['id'=>$params['id']]);
StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)],['id'=>$params['product_id']]);
} }
Db::commit(); Db::commit();
return true; return true;
@ -116,8 +116,7 @@ class StoreBranchProductLogic extends BaseLogic
{ {
$stock = StoreBranchProduct::where('id', $params['id'])->value('stock'); $stock = StoreBranchProduct::where('id', $params['id'])->value('stock');
if ($stock > 0) { if ($stock > 0) {
self::setError('商品库存不为0,无法删除'); throw new BusinessException('商品库存不为0,无法删除');
return false;
} }
StoreBranchProduct::destroy($params['id']); StoreBranchProduct::destroy($params['id']);
return true; return true;

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\store_cash_finance_flow;
use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow; use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -36,8 +37,7 @@ class StoreCashFinanceFlowLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -64,8 +64,7 @@ class StoreCashFinanceFlowLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\store_category;
use app\common\model\store_category\StoreCategory; use app\common\model\store_category\StoreCategory;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -40,8 +41,7 @@ class StoreCategoryLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -69,8 +69,7 @@ class StoreCategoryLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\store_extract;
use app\common\model\store_extract\StoreExtract; use app\common\model\store_extract\StoreExtract;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -36,8 +37,7 @@ class StoreExtractLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -61,8 +61,7 @@ class StoreExtractLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\store_finance_flow;
use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -36,8 +37,7 @@ class StoreFinanceFlowLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -61,8 +61,7 @@ class StoreFinanceFlowLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -9,13 +9,17 @@ use app\api\logic\order\OrderLogic;
use app\common\enum\PayEnum; use app\common\enum\PayEnum;
use app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\logic\CommissionnLogic;
use app\common\logic\PayNotifyLogic; use app\common\logic\PayNotifyLogic;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\user\User; use app\common\model\user\User;
use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product\WarehouseProduct; use app\common\model\warehouse_product\WarehouseProduct;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -42,17 +46,19 @@ class StoreOrderLogic extends BaseLogic
$v['uid'] = $params['user_id']; $v['uid'] = $params['user_id'];
$v['store_id'] = $params['store_id']; $v['store_id'] = $params['store_id'];
$v['cart_num'] = $v['stock']; $v['cart_num'] = $v['stock'];
StoreBranchProduct::where('id',$v['id'])->update(['price'=>$v['price'],'vip_price'=>$v['price'],'cost'=>$v['price'],'purchase'=>$v['price']]); if(in_array($params['store_id'],[17,18])){
StoreBranchProduct::where('id', $v['id'])->update(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $v['price']]);
}
unset($v['id']); unset($v['id']);
$res = CartLogic::add($v); $res = CartLogic::add($v);
$cartId[] = $res['id']; $cartId[] = $res['id'];
} }
$user = User::where('id', $params['user_id'])->find(); $user = User::where('id', $params['user_id'])->find();
$params['shipping_type']=2; $params['shipping_type'] = 2;
$params['pay_type'] = 7; $params['pay_type'] = 7;
$params['source'] =2;//后台下单
$order = OrderLogic::createOrder($cartId, null, $user, $params); $order = OrderLogic::createOrder($cartId, null, $user, $params);
return true; return true;
} }
@ -73,8 +79,7 @@ class StoreOrderLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -112,35 +117,122 @@ class StoreOrderLogic extends BaseLogic
public static function refund($detail, $params) public static function refund($detail, $params)
{ {
//微信支付 if (isset($params['product_arr']) && count($params['product_arr']) > 0) {
if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) { //微信支付
$money = (int)bcmul($detail['pay_price'], 100); if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) {
$refund = (new \app\common\logic\store_order\StoreOrderLogic()) $money = (int)bcmul($params['refund_price'], 100);
->refund($params['order_id'], $money, $money); $pay_price = (int)bcmul($detail['pay_price'], 100);
if ($refund) { $refund = (new \app\common\logic\store_order\StoreOrderLogic())
StoreOrderCartInfo::where('oid',$detail['id'])->update(['is_pay'=>-1]); ->refund($params['order_id'], $money, $pay_price);
if ($refund) {
$refund_price = $params['refund_price'];
$refund_num = 0;
foreach ($params['product_arr'] as $k => $v) {
$find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find();
if ($find) {
$refund_num += $v['cart_num'];
$cart_num = bcsub($find['cart_num'], $v['cart_num']);
$total_price = bcmul($find['price'], $cart_num);
$data = ['cart_num' => $cart_num, 'total_price' => $total_price];
StoreOrderCartInfo::where('id', $find['id'])->update($data);
$arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray();
foreach ($arr as $key => $value) {
$value['cart_num'] = $cart_num;
$value['total_price'] = bcmul($cart_num, $value['price'], 2);
$value['number'] = bcmul($value['total_price'], $value['rate'], 2);
StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]);
unset($value['id']);
$value['create_time'] = strtotime($value['create_time']);
$value['update_time'] = strtotime($value['update_time']);
StoreFinanceFlowProduct::create($value);
}
}
}
$village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid');
$brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid');
$transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id');
StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]);
$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]);
return '退款成功';
}
}
//余额支付 采购款支付
if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
PayNotifyLogic::balance_purchase_refund($detail,0,$params['refund_price']);
return '退款成功';
}
//现金支付
if ($detail['pay_type'] = PayEnum::CASH_PAY) {
PayNotifyLogic::cash_refund($params['order_id']);
return '退款成功';
}
return false;
} else {
//微信支付
if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) {
$money = (int)bcmul($detail['pay_price'], 100);
$refund = (new \app\common\logic\store_order\StoreOrderLogic())
->refund($params['order_id'], $money, $money);
if ($refund) {
StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]);
return '退款成功';
}
}
//余额支付 采购款支付
if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
PayNotifyLogic::balance_purchase_refund($detail);
StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]);
return '退款成功'; return '退款成功';
} }
//现金支付
if ($detail['pay_type'] = PayEnum::CASH_PAY) {
PayNotifyLogic::cash_refund($params['order_id']);
StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]);
return '退款成功';
}
return false;
//todo 支付包支付
} }
//余额支付 采购款支付 }
if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
$money = bcmul($detail['pay_price'], 100); public function refundProduct($detail, $params)
$arr = [ {
'amount' => [ $refund_price = $params['refund_price'];
'refund' => $money $refund_num = 0;
] foreach ($params['product_arr'] as $k => $v) {
]; $find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find();
PayNotifyLogic::refund($params['order_id'], $arr); if ($find) {
StoreOrderCartInfo::where('oid',$detail['id'])->update(['is_pay'=>-1]); $refund_num += $v['cart_num'];
return '退款成功'; $cart_num = bcsub($find['cart_num'], $v['cart_num']);
$total_price = bcmul($find['price'], $cart_num);
$data = ['cart_num' => $cart_num, 'total_price' => $total_price];
StoreOrderCartInfo::where('id', $find['id'])->update($data);
$arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray();
foreach ($arr as $key => $value) {
$value['cart_num'] = $cart_num;
$value['total_price'] = bcmul($cart_num, $value['price'], 2);
$value['number'] = bcmul($value['total_price'], $value['rate'], 2);
StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]);
unset($value['id']);
$value['create_time'] = strtotime($value['create_time']);
$value['update_time'] = strtotime($value['update_time']);
StoreFinanceFlowProduct::create($value);
}
}
} }
//现金支付 $village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid');
if ($detail['pay_type'] = PayEnum::CASH_PAY) { $brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid');
PayNotifyLogic::cash_refund($params['order_id']); $transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id');
StoreOrderCartInfo::where('oid',$detail['id'])->update(['is_pay'=>-1]); StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]);
return '退款成功'; CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id);
}
return false; StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]);
//todo 支付包支付 StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]);
} }
} }

View File

@ -4,7 +4,13 @@ namespace app\admin\logic\store_order_cart_info;
use app\admin\logic\statistic\TradeStatisticLogic; use app\admin\logic\statistic\TradeStatisticLogic;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\dict\DictData;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; 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 support\exception\BusinessException;
use think\facade\Db;
/** /**
* 订单购物详情表逻辑 * 订单购物详情表逻辑
@ -13,6 +19,151 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo;
*/ */
class StoreOrderCartInfoLogic extends BaseLogic class StoreOrderCartInfoLogic extends BaseLogic
{ {
/**
* @notes 编辑商品列表
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/05/31 10:53
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$cart_info = StoreOrderCartInfo::where('oid', $params['oid'])->find();
if($cart_info['is_pay']==1){
throw new BusinessException('已支付订单无法追加');
}
$value=DictData::where('type_value','vendors_store')->column('value');
if(!$value){
throw new BusinessException('请先配置店铺');
}
if(!in_array($cart_info['store_id'],$value)){
throw new BusinessException('该订单不属于可设置店铺');
}
foreach($params['product_arr'] as $k=>$v){
$find=StoreProduct::where('id',$v['product_id'])->find();
$cart_select['total_price'] = bcmul($v['cart_num'], $v['price'], 2); //订单总价
$cart_select['price'] = $v['price'];
$cart_select['cost'] = $v['price'];
$cart_select['vip'] = 0;
$cart_select['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name') ?? ''; //单位名称
$cart_select['purchase'] = bcmul($v['cart_num'], $v['price'], 2) ?? 0; //成本
$cart_select['pay_price'] = bcmul($v['cart_num'], $v['price'], 2); //订单支付金额
$cart_select['store_price'] = bcmul($v['cart_num'], $v['price'], 2) ?? 0; //商户价
$cart_select['vip_price'] = 0; //vip售价
$cart_select['product_id'] = $find['id'];
$cart_select['old_cart_id'] = 0;
$cart_select['cart_num'] = $v['cart_num'];
$cart_select['verify_code'] =$cart_info['verify_code'];
$cart_select['vip_frozen_price'] = 0;
$cart_select['store_info'] = $find['store_info'];
$cart_select['rose'] = $find['rose'];
$cart_select['name'] = $find['store_name'];
$cart_select['image'] = $find['image'];
$aa[$k]['cart_info'] = json_encode($cart_select);
$aa[$k]['oid'] = $cart_info['oid'];
$aa[$k]['uid']=$cart_info['uid'];
$aa[$k]['product_id']=$find['id'];
$aa[$k]['verify_code']=$cart_info['verify_code'];
$aa[$k]['price']=$v['price'];
$aa[$k]['cart_num']=$v['cart_num'];
$aa[$k]['total_price']=$cart_select['pay_price'];
}
(new StoreOrderCartInfo())->saveAll($aa);
$total_price = StoreOrderCartInfo::where('oid', $params['oid'])->sum('total_price');
$total_count = StoreOrderCartInfo::where('oid', $params['oid'])->count();
StoreOrder::where('id', $params['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
d($e);
throw new BusinessException('编辑商品失败' . $e->getMessage());
}
}
/**
* @notes 编辑商品列表
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/05/31 10:53
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
$find = StoreOrderCartInfo::where('id', $params['id'])->find();
if ($find) {
if($find['is_pay']==1){
throw new BusinessException('已支付订单无法编辑');
}
$value=DictData::where('type_value','vendors_store')->column('value');
if(!$value){
throw new BusinessException('请先配置店铺');
}
if(!in_array($find['store_id'],$value)){
throw new BusinessException('该订单不属于可设置店铺');
}
$find->cart_num = $params['cart_num'];
$find->total_price = bcmul($params['cart_num'], $find->price, 2);
$find->save();
$total_price = StoreOrderCartInfo::where('oid', $find['oid'])->sum('total_price');
$total_count = StoreOrderCartInfo::where('oid', $find['oid'])->count();
StoreOrder::where('id', $find['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]);
}
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException('编辑商品失败' . $e->getMessage());
}
}
/**
* @notes 删除商品
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/05/31 10:53
*/
public static function del(array $params): bool
{
Db::startTrans();
try {
$find = StoreOrderCartInfo::where('id', $params['id'])->find();
if ($find) {
if($find['is_pay']==1){
throw new BusinessException('已支付订单无法删除');
}
$value=DictData::where('type_value','vendors_store')->column('value');
if(!$value){
throw new BusinessException('请先配置店铺');
}
if(!in_array($find['store_id'],$value)){
throw new BusinessException('该订单不属于可设置店铺');
}
$find->delete_time=time();
$find->save();
$total_price = StoreOrderCartInfo::where('oid', $find['oid'])->sum('total_price');
$total_count = StoreOrderCartInfo::where('oid', $find['oid'])->count();
StoreOrder::where('id', $find['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]);
}
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException('删除商品失败' . $e->getMessage());
}
}
public function curve($product_id, $start_time, $end_time) public function curve($product_id, $start_time, $end_time)
{ {
$store_order_cart_info = new StoreOrderCartInfo(); $store_order_cart_info = new StoreOrderCartInfo();
@ -29,13 +180,13 @@ class StoreOrderCartInfoLogic extends BaseLogic
$totalCartNum2 = $store_order_cart_info->getCurveData($where, $time, 'sum(total_price)'); $totalCartNum2 = $store_order_cart_info->getCurveData($where, $time, 'sum(total_price)');
$totalCartNum2 = $tradeStatisticLogic->trendYdata((array)$totalCartNum2, $timeKey); $totalCartNum2 = $tradeStatisticLogic->trendYdata((array)$totalCartNum2, $timeKey);
$value1=[]; $value1 = [];
$value2=[]; $value2 = [];
foreach($totalCartNum1['y'] as $k=>$v){ foreach ($totalCartNum1['y'] as $k => $v) {
$value1[]=$v; $value1[] = $v;
} }
foreach($totalCartNum2['y'] as $k=>$v){ foreach ($totalCartNum2['y'] as $k => $v) {
$value2[]=$v; $value2[] = $v;
} }
$data = []; $data = [];
$data['xAxis'] = $totalCartNum1['x'] ?? []; $data['xAxis'] = $totalCartNum1['x'] ?? [];
@ -45,9 +196,9 @@ class StoreOrderCartInfoLogic extends BaseLogic
'smooth' => 'true', 'smooth' => 'true',
'type' => 'line', 'type' => 'line',
'yAxisIndex' => 1, 'yAxisIndex' => 1,
'value' =>$value1 'value' => $value1
] ],
,[ [
'name' => '金额', 'name' => '金额',
'smooth' => 'true', 'smooth' => 'true',
'type' => 'line', 'type' => 'line',

View File

@ -36,13 +36,25 @@ class StoreProductLogic extends BaseLogic
*/ */
public static function add(array $params): bool public static function add(array $params): bool
{ {
$count=count($params['cate_arr']);
$top_cate_id=0;
$two_cate_id=0;
if($count==3){
$top_cate_id=$params['cate_arr'][0];
$two_cate_id=$params['cate_arr'][1];
}elseif($count==2){
$top_cate_id=$params['cate_arr'][0];
$two_cate_id=$params['cate_arr'][0];
}
Db::startTrans(); Db::startTrans();
try { try {
$data = [ $data = [
'store_name' => $params['store_name'], 'store_name' => $params['store_name'],
'image' => $params['image'], 'image' => $params['image'],
'store_info' => $params['store_info'] ?? '', 'store_info' => $params['store_info'] ?? '',
'bar_code' =>$params['product_arr'][0]['bar_code'] ?? '', 'bar_code' => $params['bar_code'] ?? '',
'top_cate_id' => $top_cate_id,
'two_cate_id' => $two_cate_id,
'cate_id' => $params['cate_id'], 'cate_id' => $params['cate_id'],
'unit' => $params['product_arr'][0]['unit'], 'unit' => $params['product_arr'][0]['unit'],
'stock' => 0, 'stock' => 0,
@ -57,8 +69,14 @@ class StoreProductLogic extends BaseLogic
'batch' => $params['batch'] ?? 0, 'batch' => $params['batch'] ?? 0,
'store_batch' => $params['store_batch'] ?? 1, 'store_batch' => $params['store_batch'] ?? 1,
'product_type' => $params['product_type'] ?? 0, 'product_type' => $params['product_type'] ?? 0,
'spec_type' => $params['spec_type'] ?? 0, 'is_show' => $params['is_show'] ?? 0,
]; ];
// if ($params['rose'] > 0) {
// $rose_price = bcmul($params['cost'], $params['rose'], 2);
// $data['price'] = bcadd($params['cost'], $rose_price, 2);
// } else {
// $data['price'] = 0;
// }
$res = StoreProduct::create($data); $res = StoreProduct::create($data);
$arr=[]; $arr=[];
foreach($params['product_arr'] as $k=>$v){ foreach($params['product_arr'] as $k=>$v){
@ -76,8 +94,7 @@ class StoreProductLogic extends BaseLogic
return true; return true;
} catch (\Throwable $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
d($e); throw new BusinessException('添加商品失败'.$e->getMessage());
throw new BusinessException($e->getMessage());
} }
} }
@ -146,11 +163,23 @@ class StoreProductLogic extends BaseLogic
{ {
Db::startTrans(); Db::startTrans();
try { try {
$count=count($params['cate_arr']);
$top_cate_id=0;
$two_cate_id=0;
if($count==3){
$top_cate_id=$params['cate_arr'][0];
$two_cate_id=$params['cate_arr'][1];
}elseif($count==2){
$top_cate_id=$params['cate_arr'][0];
$two_cate_id=$params['cate_arr'][0];
}
$data = [ $data = [
'store_name' => $params['store_name'], 'store_name' => $params['store_name'],
'image' => $params['image'], 'image' => $params['image'],
'bar_code' => $params['bar_code'] ?? '', 'bar_code' => $params['bar_code'] ?? '',
'store_info' => $params['store_info'] ?? '', 'store_info' => $params['store_info'] ?? '',
'top_cate_id' => $top_cate_id,
'two_cate_id' => $two_cate_id,
'cate_id' => $params['cate_id'], 'cate_id' => $params['cate_id'],
'unit' => $params['unit'], 'unit' => $params['unit'],
'stock' => $params['stock'], 'stock' => $params['stock'],
@ -164,14 +193,14 @@ class StoreProductLogic extends BaseLogic
'store_batch' => $params['store_batch'] ?? 1, 'store_batch' => $params['store_batch'] ?? 1,
'manufacturer_information' => $params['manufacturer_information'] ?? '', 'manufacturer_information' => $params['manufacturer_information'] ?? '',
'swap' => $params['swap'] ?? 0, 'swap' => $params['swap'] ?? 0,
'rose' => $params['rose'] ?? 0, 'is_show' => $params['is_show'] ?? 0,
]; ];
StoreProduct::where('id', $params['id'])->update($data); StoreProduct::update($data,['id'=>$params['id']]);
$dealCate = self::dealChangeCate($params['cate_id']); // $dealCate = self::dealChangeCate($params['cate_id']);
//修改 //修改
StoreBranchProduct::where('product_id', $params['id'])->update([ StoreBranchProduct::where('product_id', $params['id'])->whereNotIn('store_id',[17,18])->update([
'price' => $params['price'], 'price' => $params['price'],
'vip_price' => $params['vip_price'], 'vip_price' => $params['vip_price'],
'cost' => $params['cost'], 'cost' => $params['cost'],
@ -181,11 +210,13 @@ class StoreProductLogic extends BaseLogic
'manufacturer_information' => $params['manufacturer_information'] ?? '', 'manufacturer_information' => $params['manufacturer_information'] ?? '',
'store_info' => $params['store_info'] ?? '', 'store_info' => $params['store_info'] ?? '',
'cate_id' => $params['cate_id'], 'cate_id' => $params['cate_id'],
'top_cate_id' => $dealCate['top_cate_id'], 'top_cate_id' => $top_cate_id,
'two_cate_id' => $dealCate['two_cate_id'], 'two_cate_id' => $two_cate_id,
'cate_id' => $params['cate_id'],
'bar_code' => $params['bar_code'], 'bar_code' => $params['bar_code'],
'purchase' => $params['purchase'], 'purchase' => $params['purchase'],
'rose' => $params['rose'] ?? 0, 'rose' => $params['rose'] ?? 0,
'status' => $params['is_show'] ?? 0,
'image' => $params['image'], 'image' => $params['image'],
'store_batch' => $params['store_batch'] ?? 1, 'store_batch' => $params['store_batch'] ?? 1,
@ -193,10 +224,10 @@ class StoreProductLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException('编辑商品失败'.$e->getMessage());
return false;
} }
} }
@ -255,8 +286,8 @@ class StoreProductLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException('删除失败'.$e->getMessage());
return false;
} }
} }
@ -264,6 +295,10 @@ class StoreProductLogic extends BaseLogic
/**普通 */ /**普通 */
public static function ordinary($product_arr, $store_id, $admin_id, $find) public static function ordinary($product_arr, $store_id, $admin_id, $find)
{ {
$res=StoreBranchProduct::where('store_id',$store_id)->where('product_id',$find['id'])->find();
if($res){
return $res;
}
$dealCate = self::dealChangeCate($find['cate_id']); $dealCate = self::dealChangeCate($find['cate_id']);
$product = [ $product = [
'product_id' => $find['id'], 'product_id' => $find['id'],
@ -331,8 +366,7 @@ class StoreProductLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); throw new BusinessException('添加兑换商品失败'.$e->getMessage());
return false;
} }
} }
// else { // else {

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\store_product_attr_value;
use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -36,8 +37,7 @@ class StoreProductAttrValueLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -61,8 +61,7 @@ class StoreProductAttrValueLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\store_product_unit;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -40,8 +41,7 @@ class StoreProductUnitLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -69,8 +69,7 @@ class StoreProductUnitLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\supplier;
use app\common\model\supplier\Supplier; use app\common\model\supplier\Supplier;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -41,8 +42,7 @@ class SupplierLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -71,8 +71,7 @@ class SupplierLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -6,6 +6,7 @@ namespace app\admin\logic\system_store;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\system_store\SystemStoreStaff; use app\common\model\system_store\SystemStoreStaff;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
use Webman\Config; use Webman\Config;
@ -70,8 +71,8 @@ class SystemStoreLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -137,8 +138,8 @@ class SystemStoreLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -10,6 +10,7 @@ use app\common\logic\BaseLogic;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\warehouse_product\WarehouseProduct; use app\common\model\warehouse_product\WarehouseProduct;
use app\common\model\warehouse_product_storege\WarehouseProductStorege; use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -44,10 +45,9 @@ class SystemStoreStorageLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -74,8 +74,8 @@ class SystemStoreStorageLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -21,6 +21,7 @@ use app\common\model\tools\GenerateTable;
use app\common\service\generator\GenerateService; use app\common\service\generator\GenerateService;
use support\Cache; use support\Cache;
use support\Container; use support\Container;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -78,8 +79,7 @@ class GeneratorLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::$error = $e->getMessage(); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -134,8 +134,7 @@ class GeneratorLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::$error = $e->getMessage(); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -157,8 +156,7 @@ class GeneratorLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::$error = $e->getMessage(); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -187,8 +185,7 @@ class GeneratorLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::$error = $e->getMessage(); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -228,8 +225,7 @@ class GeneratorLogic extends BaseLogic
return ['file' => $zipFile]; return ['file' => $zipFile];
} catch (\Exception $e) { } catch (\Exception $e) {
self::$error = $e->getMessage(); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -252,8 +248,7 @@ class GeneratorLogic extends BaseLogic
return Container::get(GenerateService::class)->preview($table); return Container::get(GenerateService::class)->preview($table);
} catch (\Exception $e) { } catch (\Exception $e) {
self::$error = $e->getMessage(); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\user;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\user\UserFeedback; use app\common\model\user\UserFeedback;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -40,8 +41,7 @@ class UserFeedbackLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -69,8 +69,7 @@ class UserFeedbackLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -31,6 +31,7 @@ use app\common\model\user_sign\UserSign;
use app\common\model\vip_flow\VipFlow; use app\common\model\vip_flow\VipFlow;
use think\facade\Db; use think\facade\Db;
use app\common\service\FileService; use app\common\service\FileService;
use support\exception\BusinessException;
use Webman\Config; use Webman\Config;
/** /**
@ -69,10 +70,9 @@ class UserLogic extends BaseLogic
Db::commit(); Db::commit();
return $res; return $res;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -81,23 +81,19 @@ class UserLogic extends BaseLogic
$user_ship=$params['user_ship']??0; $user_ship=$params['user_ship']??0;
if($user_ship==2){ if($user_ship==2){
if(!isset($params['village'])){ if(!isset($params['village'])){
self::setError('请设置村参数'); throw new BusinessException('请设置村参数');
return false;
} }
$arr=User::where('user_ship',$user_ship)->alias('user')->join('user_address address','user.id=address.uid and village='.$params['village'])->find(); $arr=User::where('user_ship',$user_ship)->alias('user')->join('user_address address','user.id=address.uid and village='.$params['village'])->find();
if ($arr) { if ($arr) {
self::setError('该区域已有村长请重新选择'); throw new BusinessException('该区域已有村长请重新选择');
return false;
} }
}elseif($user_ship==3){ }elseif($user_ship==3){
if(!isset($params['brigade'])){ if(!isset($params['brigade'])){
self::setError('请设置队参数'); throw new BusinessException('请设置队参数');
return false;
} }
$arr=User::where('user_ship',$user_ship)->alias('user')->join('user_address address','user.id=address.uid and village='.$params['village'] .' and brigade='.$params['brigade'])->find(); $arr=User::where('user_ship',$user_ship)->alias('user')->join('user_address address','user.id=address.uid and village='.$params['village'] .' and brigade='.$params['brigade'])->find();
if($arr){ if($arr){
self::setError('该区域已有队长请重新选择'); throw new BusinessException('该区域已有队长请重新选择');
return false;
} }
} }
return true; return true;
@ -148,8 +144,7 @@ class UserLogic extends BaseLogic
return $res; return $res;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
/** /**
@ -179,8 +174,7 @@ class UserLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\user_bill;
use app\common\model\user_bill\UserBill; use app\common\model\user_bill\UserBill;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -36,8 +37,7 @@ class UserBillLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -61,8 +61,7 @@ class UserBillLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\user_label;
use app\common\model\user_label\UserLabel; use app\common\model\user_label\UserLabel;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -36,8 +37,7 @@ class UserLabelLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -61,8 +61,8 @@ class UserLabelLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\user_recharge;
use app\common\model\user_recharge\UserRecharge; use app\common\model\user_recharge\UserRecharge;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -36,8 +37,8 @@ class UserRechargeLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -61,8 +62,8 @@ class UserRechargeLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -7,6 +7,7 @@ use app\common\model\user_ship\UserShip;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\user\User; use app\common\model\user\User;
use app\common\model\user\UserAddress; use app\common\model\user\UserAddress;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -40,8 +41,8 @@ class UserShipLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -67,8 +68,8 @@ class UserShipLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -106,8 +107,7 @@ class UserShipLogic extends BaseLogic
$user_ship=$params['user_ship']??0; $user_ship=$params['user_ship']??0;
if($user_ship==2){ if($user_ship==2){
if(!isset($params['village'])){ if(!isset($params['village'])){
self::setError('请设置村参数'); throw new BusinessException('请设置村参数');
return false;
} }
$arr=User::where('user_ship',$user_ship)->column('id'); $arr=User::where('user_ship',$user_ship)->column('id');
if($arr){ if($arr){
@ -116,14 +116,12 @@ class UserShipLogic extends BaseLogic
if($params['uid']==$find['uid']){ if($params['uid']==$find['uid']){
return true; return true;
} }
self::setError('该区域已有村长请重新选择'); throw new BusinessException('该区域已有村长请重新选择');
return false;
} }
} }
}elseif($user_ship==3){ }elseif($user_ship==3){
if(!isset($params['brigade'])){ if(!isset($params['brigade'])){
self::setError('请设置队参数'); throw new BusinessException('请设置队参数');
return false;
} }
$arr=User::where('user_ship',$user_ship)->column('id'); $arr=User::where('user_ship',$user_ship)->column('id');
if($arr){ if($arr){
@ -132,8 +130,7 @@ class UserShipLogic extends BaseLogic
if($params['uid']==$find['uid']){ if($params['uid']==$find['uid']){
return true; return true;
} }
self::setError('该区域已有队长请重新选择'); throw new BusinessException('该区域已有队长请重新选择');
return false;
} }
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\warehouse;
use app\common\model\warehouse\Warehouse; use app\common\model\warehouse\Warehouse;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -42,8 +43,8 @@ class WarehouseLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -73,8 +74,8 @@ class WarehouseLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -6,6 +6,7 @@ use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_order\WarehouseOrder;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\warehouse_product\WarehouseProduct; use app\common\model\warehouse_product\WarehouseProduct;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
/** /**
@ -69,10 +70,9 @@ class WarehouseOrderLogic extends BaseLogic
} }
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -88,8 +88,7 @@ class WarehouseOrderLogic extends BaseLogic
{ {
$find = WarehouseOrder::where('id', $params['id'])->find(); $find = WarehouseOrder::where('id', $params['id'])->find();
if (!$find) { if (!$find) {
self::setError('订单不存在'); throw new BusinessException('订单不存在');
return false;
} }
Db::startTrans(); Db::startTrans();
try { try {
@ -128,8 +127,7 @@ class WarehouseOrderLogic extends BaseLogic
return true; return true;
} catch (\Throwable $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -145,8 +143,7 @@ class WarehouseOrderLogic extends BaseLogic
{ {
$count = WarehouseProduct::where('oid', $params['id'])->count(); $count = WarehouseProduct::where('oid', $params['id'])->count();
if ($count >= 1) { if ($count >= 1) {
self::setError('该订单下还有商品没有删除,请先删除商品'); throw new BusinessException('该订单下还有商品没有删除,请先删除商品');
return false;
} }
WarehouseOrder::destroy($params['id']); WarehouseOrder::destroy($params['id']);
$find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find(); $find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();

View File

@ -42,15 +42,22 @@ class WarehouseProductLogic extends BaseLogic
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find(); $storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
if ($storege) { if ($storege) {
if ($params['financial_pm'] == 0) { if ($params['financial_pm'] == 0) {
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
if (!$storeProduct) {
throw new BusinessException('商品不存在');
}
$after_nums = $storege['nums'] - $params['nums']; $after_nums = $storege['nums'] - $params['nums'];
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
// if ($after_nums < 0) { // if ($after_nums < 0) {
// throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']); // throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']);
// } // }
WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update(); WarehouseProductStorege::update(['nums'=>$after_nums, 'total_price' => $total_price],['id'=> $storege['id']]);
//门店加库存 //门店加库存
$storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['store_id'])->find(); $storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['store_id'])->find();
if (!$storeBranchProduct) { if (!$storeBranchProduct) {
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray(); $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
if (!$storeProduct) { if (!$storeProduct) {
throw new BusinessException('商品不存在'); throw new BusinessException('商品不存在');
} }
@ -62,28 +69,32 @@ class WarehouseProductLogic extends BaseLogic
} else { } else {
$after_nums = $storege['nums'] + $params['nums']; $after_nums = $storege['nums'] + $params['nums'];
if ($type == 1) { if ($type == 1) {
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray(); $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
if (!$storeProduct) { if (!$storeProduct) {
throw new BusinessException('商品不存在'); throw new BusinessException('商品不存在');
} }
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2); $total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
WarehouseProductStorege::where('id', $storege['id'])->update(['nums' => $after_nums, 'total_price' => $total_price]); WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price],['id'=>$storege['id']]);
} }
} }
$before_nums = $storege['nums']; $before_nums = $storege['nums'];
} else { } else {
$after_nums = $params['nums']; $after_nums = $params['nums'];
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray(); $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
if (!$storeProduct) { if (!$storeProduct) {
throw new BusinessException('商品不存在'); throw new BusinessException('商品不存在');
} }
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2); $total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
WarehouseProductStorege::create([ $data=[
'warehouse_id' => $params['warehouse_id'], 'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'], 'product_id' => $params['product_id'],
'nums' => $params['nums'], 'nums' => $params['nums'],
'total_price'=>$total_price 'total_price'=>$total_price
]); ];
if($params['financial_pm']==0){
$data['nums']=-$params['nums'];
}
$storege=WarehouseProductStorege::create($data);
} }
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count(); $batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count();
$data = [ $data = [
@ -208,8 +219,7 @@ class WarehouseProductLogic extends BaseLogic
} elseif ($res['financial_pm'] == 0) { } elseif ($res['financial_pm'] == 0) {
$stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock'); $stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock');
if ($stock < $res['nums']) { if ($stock < $res['nums']) {
self::setError('商品库存不足,无法退回'); throw new BusinessException('商品库存不足,无法退回');
return false;
} }
StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update(); StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update();
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update(); WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update();
@ -223,9 +233,30 @@ class WarehouseProductLogic extends BaseLogic
} }
return true; return true;
} }
return false; throw new BusinessException('没有查到出入库信息');
} }
/**
* * @notes 结算
* @param $id
* @return void
*/
public static function settlement($id){
Db::startTrans();
try {
$find=WarehouseProduct::where(['id'=>$id,'financial_pm'=>1,'is_pay'=>0])->find();
if($find){
$find->is_pay=1;
$find->save();
} else{
throw new BusinessException('没有查到出入库信息');
}
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
throw new BusinessException($th->getMessage());
}
}
/** /**
* @notes 获取商品仓储信息详情 * @notes 获取商品仓储信息详情
* @param $params * @param $params

View File

@ -52,7 +52,7 @@ class SupplierValidate extends BaseValidate
*/ */
public function sceneAdd() public function sceneAdd()
{ {
return $this->only(['mer_name','phone','settle_cycle','address','mark','status']); return $this->only(['mer_name','phone','settle_cycle','address']);
} }
@ -64,7 +64,7 @@ class SupplierValidate extends BaseValidate
*/ */
public function sceneEdit() public function sceneEdit()
{ {
return $this->only(['id','mer_name','phone','settle_cycle','address','mark','status']); return $this->only(['id','mer_name','phone','settle_cycle','address']);
} }

View File

@ -44,9 +44,20 @@ class IndexController extends BaseApiController
public function index() public function index()
{ {
return json([1]); return json(1);
$financeFlow = new StoreFinanceFlow();
$financeFlowLogic = new StoreFinanceFlowLogic();
$select_1 = $financeFlow->where('id',16197)->select();
foreach ($select_1 as $k => $v) {
if ($v['other_uid'] > 0) {
$financeFlowLogic->updateStatusUser($v['id'], $v['other_uid'], $v['number'], $v['order_id']);
}
}
} }
/** /**
* @notes 下载文件 * @notes 下载文件
*/ */
@ -135,9 +146,8 @@ class IndexController extends BaseApiController
$latitude = $params['lat']; $latitude = $params['lat'];
$longitude = $params['long']; $longitude = $params['long'];
// 计算距离的SQL表达式 // 计算距离的SQL表达式
$distanceSql = "SQRT(POW(69.1 * (latitude - {$latitude}), 2) + $distanceExpr = "6371 * 2 * ASIN(SQRT(POWER(SIN(({$latitude} - abs(latitude)) * pi()/180 / 2), 2) + COS({$latitude} * pi()/180) * COS(abs(latitude) * pi()/180) * POWER(SIN(({$longitude} - longitude) * pi()/180 / 2), 2)))";
POW(69.1 * ({$longitude} - longitude) * COS(latitude / 57.3), 2))"; $find = SystemStore::field("id, name,abbreviation, {$distanceExpr} AS distance")
$find = SystemStore::field("id, name,abbreviation, {$distanceSql} AS distance")
->where('is_show', '=', 1) ->where('is_show', '=', 1)
->where('latitude', '<>', '') ->where('latitude', '<>', '')
->where('longitude', '<>', '') ->where('longitude', '<>', '')

View File

@ -19,9 +19,6 @@ class LoginController extends BaseApiController
{ {
$params = (new LoginAccountValidate())->post()->goCheck(); $params = (new LoginAccountValidate())->post()->goCheck();
$result = LoginLogic::login($params); $result = LoginLogic::login($params);
if (false === $result) {
return $this->fail(LoginLogic::getError());
}
return $this->success('', $result); return $this->success('', $result);
} }
/** /**
@ -44,9 +41,6 @@ class LoginController extends BaseApiController
{ {
$params = (new WechatLoginValidate())->post()->goCheck('mnpLogin'); $params = (new WechatLoginValidate())->post()->goCheck('mnpLogin');
$res = LoginLogic::mnpLogin($params); $res = LoginLogic::mnpLogin($params);
if (false === $res) {
return $this->fail(LoginLogic::getError());
}
$res = LoginLogic::dealStaff($res); $res = LoginLogic::dealStaff($res);
return $this->success('', $res); return $this->success('', $res);
} }
@ -63,9 +57,6 @@ class LoginController extends BaseApiController
$params = (new WechatLoginValidate())->post()->goCheck("wechatAuth"); $params = (new WechatLoginValidate())->post()->goCheck("wechatAuth");
$params['user_id'] = $this->userId; $params['user_id'] = $this->userId;
$result = LoginLogic::mnpAuthLogin($params); $result = LoginLogic::mnpAuthLogin($params);
if ($result === false) {
return $this->fail(LoginLogic::getError());
}
return $this->success('绑定成功', [], 1, 1); return $this->success('绑定成功', [], 1, 1);
} }
@ -79,9 +70,6 @@ class LoginController extends BaseApiController
{ {
$params = $this->request->post(); $params = $this->request->post();
$result = LoginLogic::updateUser($params, $this->userId); $result = LoginLogic::updateUser($params, $this->userId);
if ($result === false) {
return $this->fail(LoginLogic::getError());
}
return $this->success('操作成功', [], 1, 0); return $this->success('操作成功', [], 1, 0);
} }

View File

@ -6,8 +6,9 @@ use app\api\logic\order\CartLogic;
use app\api\validate\CartValidate; use app\api\validate\CartValidate;
use app\api\controller\BaseApiController; use app\api\controller\BaseApiController;
use app\api\lists\order\CartList; use app\api\lists\order\CartList;
use app\api\lists\order\CartWholesaleList;
use app\common\model\order\Cart; use app\common\model\order\Cart;
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\store_product_unit\StoreProductUnit;
class CartController extends BaseApiController class CartController extends BaseApiController
@ -16,7 +17,13 @@ class CartController extends BaseApiController
{ {
return $this->dataLists(new CartList()); return $this->dataLists(new CartList());
} }
/**
* 批发商品列表
*/
public function wholesale_lists(){
return $this->dataLists(new CartWholesaleList());
}
/** /**
* @notes 添加购物车 * @notes 添加购物车
*/ */
@ -25,18 +32,16 @@ class CartController extends BaseApiController
$params = (new CartValidate())->post()->goCheck('add'); $params = (new CartValidate())->post()->goCheck('add');
$params['uid'] = $this->request->userId; $params['uid'] = $this->request->userId;
$result = Cart::where(['uid' => $params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0, 'delete_time' => null])->find(); $result = Cart::where(['uid' => $params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0, 'delete_time' => null])->find();
$params['cart_num']=bcadd($params['cart_num'],0,2);
//判断起批发价 //判断起批发价
$branchProduct = StoreBranchProduct::where( $branchProduct = StoreProduct::where(
[ [
'product_id' => $params['product_id'], 'id' => $params['product_id'],
'store_id' => $params['store_id']
] ]
)->find(); )->find();
if (!$branchProduct) { if (!$branchProduct) {
return $this->fail('商品不存在'); return $this->fail('商品不存在');
} }
$params['cart_num']=intval($params['cart_num']);
if ($params['cart_num'] < $branchProduct['batch']) { if ($params['cart_num'] < $branchProduct['batch']) {
return $this->fail('起批发量低于最低值' . $branchProduct['batch']); return $this->fail('起批发量低于最低值' . $branchProduct['batch']);
} }
@ -85,12 +90,23 @@ class CartController extends BaseApiController
{ {
$params = (new CartValidate())->post()->goCheck('change'); $params = (new CartValidate())->post()->goCheck('change');
$params['uid'] = $this->request->userId; $params['uid'] = $this->request->userId;
$params['cart_num']=intval($params['cart_num']); $params['cart_num']=bcadd($params['cart_num'],0,2);
if (convertNumber($params['cart_num']) === false) {
$branchProduct = StoreProduct::where(
[
'id' => $params['product_id'],
]
)->find();
$is_bulk = StoreProductUnit::where('id', $branchProduct['unit'])->value('is_bulk');
if ($is_bulk == 0) {
return $this->fail('非计量商品,不能有小数,请编辑购物车');
}
}
$res = CartLogic::edit($params, 'dec'); $res = CartLogic::edit($params, 'dec');
if ($res) { if ($res) {
return $this->success('修改成功'); return $this->success('修改成功');
} else { } else {
return $this->fail(CartLogic::getError()); return $this->fail('修改失败');
} }
} }
@ -105,7 +121,7 @@ class CartController extends BaseApiController
if ($res) { if ($res) {
return $this->success('删除成功'); return $this->success('删除成功');
} else { } else {
return $this->fail(CartLogic::getError()); return $this->fail('删除失败');
} }
} }
} }

View File

@ -105,13 +105,6 @@ class OrderController extends BaseApiController
$params = $this->request->post(); $params = $this->request->post();
$user = User::where('id', $this->userId)->find(); $user = User::where('id', $this->userId)->find();
$res = OrderLogic::cartIdByOrderInfo($cartId, $addressId, $user, $params); $res = OrderLogic::cartIdByOrderInfo($cartId, $addressId, $user, $params);
if ($res == false) {
$msg = OrderLogic::getError();
if ($msg == '购物车为空') {
return $this->data([]);
}
return $this->fail(OrderLogic::getError());
}
return $this->data($res); return $this->data($res);
} }
@ -119,13 +112,6 @@ class OrderController extends BaseApiController
{ {
$params = (new OrderValidate())->post()->goCheck('cart'); $params = (new OrderValidate())->post()->goCheck('cart');
$res = OrderLogic::checkLeft($params, $this->userId); $res = OrderLogic::checkLeft($params, $this->userId);
if (!$res) {
$msg = OrderLogic::getError();
if ($msg == '购物车为空') {
return $this->data([]);
}
return $this->fail(OrderLogic::getError());
}
return $this->data($res); return $this->data($res);
} }
@ -230,8 +216,6 @@ class OrderController extends BaseApiController
return $this->fail('支付方式错误'); return $this->fail('支付方式错误');
} }
// return $this->data(['order_id' => $order->id]); // return $this->data(['order_id' => $order->id]);
} else {
return $this->fail(OrderLogic::getError());
} }
} }
@ -306,17 +290,11 @@ class OrderController extends BaseApiController
} }
} }
$result = PaymentLogic::pay($pay_type, 'wechat_common', $order, $this->userInfo['terminal'] ?? 1, $redirectUrl); $result = PaymentLogic::pay($pay_type, 'wechat_common', $order, $this->userInfo['terminal'] ?? 1, $redirectUrl);
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError());
}
return $this->success('', $result); return $this->success('', $result);
break; break;
case PayEnum::WECHAT_PAY_BARCODE: case PayEnum::WECHAT_PAY_BARCODE:
//微信条码支付 //微信条码支付
$result = PaymentLogic::codepay($auth_code, $order); $result = PaymentLogic::codepay($auth_code, $order);
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params);
}
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
PayNotifyLogic::handle('StoreOrder', $result['out_trade_no'], $result); PayNotifyLogic::handle('StoreOrder', $result['out_trade_no'], $result);
} else { } else {
@ -336,9 +314,6 @@ class OrderController extends BaseApiController
case PayEnum::ALIPAY_BARCODE: case PayEnum::ALIPAY_BARCODE:
//支付宝条码支付 //支付宝条码支付
$result = PaymentLogic::ali_auth_code($auth_code, $order); $result = PaymentLogic::ali_auth_code($auth_code, $order);
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params);
}
if ($result['msg'] !== 'Success') { if ($result['msg'] !== 'Success') {
return $this->success('用户支付中'); return $this->success('用户支付中');
} }
@ -388,11 +363,8 @@ class OrderController extends BaseApiController
{ {
$params = $this->request->get(); $params = $this->request->get();
$res = OrderLogic::frequentlyPurchase($params); $res = OrderLogic::frequentlyPurchase($params);
if (OrderLogic::hasError()) { return $this->data($res);
return $this->fail(OrderLogic::getError());
} else {
return $this->data($res);
}
} }
/** /**
@ -466,7 +438,7 @@ class OrderController extends BaseApiController
if ($res) { if ($res) {
return $this->success('核销成功'); return $this->success('核销成功');
} }
return $this->fail('核销失败' . OrderLogic::getError()); return $this->fail('核销失败');
} }
@ -476,7 +448,7 @@ class OrderController extends BaseApiController
$date = $this->request->get('date', date('Y-m-d')); $date = $this->request->get('date', date('Y-m-d'));
$store_id = SystemStoreStaff::where('phone', $this->userInfo['mobile'])->value('store_id'); $store_id = SystemStoreStaff::where('phone', $this->userInfo['mobile'])->value('store_id');
if (empty($store_id)) { if (empty($store_id)) {
throw new \Exception('该用户未绑定店铺'); return $this->fail('该用户未绑定店铺');
} }
$where[] = ['store_id', '=', $store_id]; $where[] = ['store_id', '=', $store_id];
$where[] = ['paid', '=', 1]; $where[] = ['paid', '=', 1];

View File

@ -3,11 +3,14 @@
namespace app\api\controller\product; namespace app\api\controller\product;
use app\api\controller\BaseApiController; use app\api\controller\BaseApiController;
use app\api\lists\product\ProductLists; use app\api\lists\product\ProductLists;
use app\api\lists\product\ProductWholesaleLists;
use app\api\lists\product\StoreProductLists; use app\api\lists\product\StoreProductLists;
use app\common\model\system_store\SystemStoreStaff; use app\common\model\system_store\SystemStoreStaff;
class ProductController extends BaseApiController{ class ProductController extends BaseApiController{
public $notNeedLogin = ['lists']; public $notNeedLogin = ['lists'];
/** /**
* 商品列表 * 商品列表
*/ */
@ -16,6 +19,13 @@ class ProductController extends BaseApiController{
return $this->dataLists(new ProductLists()); return $this->dataLists(new ProductLists());
} }
/**
* 批发商品列表
*/
public function wholesale_lists(){
return $this->dataLists(new ProductWholesaleLists());
}
/** /**
* 商品列表 * 商品列表
*/ */

View File

@ -89,20 +89,11 @@ class StoreController extends BaseApiController
$params['create_uid']=$this->userId; $params['create_uid']=$this->userId;
if(isset($params['user_ship']) && in_array($params['user_ship'],[2,3])){ if(isset($params['user_ship']) && in_array($params['user_ship'],[2,3])){
UserUserLogic::checkAddress($params); UserUserLogic::checkAddress($params);
if(UserUserLogic::hasError()){
return $this->fail(UserUserLogic::getError());
}
} }
$find=UserUserLogic::StoreAdd($params); $find=UserUserLogic::StoreAdd($params);
if(UserUserLogic::hasError()){
return $this->fail(UserUserLogic::getError());
}
}else{ }else{
if($find['user_ship']!=$params['user_ship'] && in_array($params['user_ship'],[2,3])){ if($find['user_ship']!=$params['user_ship'] && in_array($params['user_ship'],[2,3])){
UserUserLogic::checkAddress($params); UserUserLogic::checkAddress($params);
if(UserUserLogic::hasError()){
return $this->fail(UserUserLogic::getError());
}
} }
$find['real_name']=$params['real_name']; $find['real_name']=$params['real_name'];
$find['label_id']=$params['label_id']??0; $find['label_id']=$params['label_id']??0;
@ -144,9 +135,6 @@ class StoreController extends BaseApiController
$order['pay_price']=$order['price']; $order['pay_price']=$order['price'];
$order['attach']='recharge'; $order['attach']='recharge';
$result = PaymentLogic::codepay($auth_code, $order,'条码支付'); $result = PaymentLogic::codepay($auth_code, $order,'条码支付');
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError());
}
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
Cache::set('trade_state' . time(), json_encode($result)); Cache::set('trade_state' . time(), json_encode($result));
PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result); PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result);
@ -181,9 +169,6 @@ class StoreController extends BaseApiController
$order['pay_price']=$order['price']; $order['pay_price']=$order['price'];
$order['attach']='recharge'; $order['attach']='recharge';
$result = PaymentLogic::codepay($auth_code, $order,'条码支付'); $result = PaymentLogic::codepay($auth_code, $order,'条码支付');
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError());
}
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result); PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result);
} else { } else {

View File

@ -23,11 +23,8 @@ class AddressController extends BaseApiController
$params = (new UserAddressValidate())->post()->goCheck('add'); $params = (new UserAddressValidate())->post()->goCheck('add');
$params['uid'] = $this->request->userId; $params['uid'] = $this->request->userId;
$res=AddressLogic::add($params); $res=AddressLogic::add($params);
if(AddressLogic::hasError()){ return $this->success('添加成功');
return $this->fail(AddressLogic::getError());
}else{
return $this->success('添加成功');
}
} }
/** /**
* 商户给用户添加地址 * 商户给用户添加地址
@ -62,9 +59,8 @@ class AddressController extends BaseApiController
$params['uid'] = $this->request->userId; $params['uid'] = $this->request->userId;
if(AddressLogic::edit($params)){ if(AddressLogic::edit($params)){
return $this->success('编辑成功'); return $this->success('编辑成功');
}else{
return $this->fail(AddressLogic::getError());
} }
return $this->fail('编辑失败');
} }

View File

@ -42,9 +42,7 @@ class UserController extends BaseApiController
$params = (new UserValidate())->post()->goCheck('getMobileByMnp'); $params = (new UserValidate())->post()->goCheck('getMobileByMnp');
$params['user_id'] = $this->userId; $params['user_id'] = $this->userId;
$result = UserLogic::getMobileByMnp($params); $result = UserLogic::getMobileByMnp($params);
if ($result === false) {
return $this->fail(UserLogic::getError());
}
if ($result && is_numeric($result)) { if ($result && is_numeric($result)) {
$data = UserLogic::info($result); $data = UserLogic::info($result);
$userInfo = UserTokenService::setToken($result, 1); $userInfo = UserTokenService::setToken($result, 1);
@ -104,9 +102,6 @@ class UserController extends BaseApiController
$order = UserLogic::recharge($params); $order = UserLogic::recharge($params);
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment'; $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
$result = PaymentLogic::pay(PayEnum::WECHAT_PAY_MINI, 'recharge', $order, $this->userInfo['terminal'], $redirectUrl); $result = PaymentLogic::pay(PayEnum::WECHAT_PAY_MINI, 'recharge', $order, $this->userInfo['terminal'], $redirectUrl);
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params);
}
return $this->success('', $result); return $this->success('', $result);
} }

View File

@ -30,6 +30,6 @@
if (true === $result) { if (true === $result) {
return $this->success('添加成功', [], 1, 1); return $this->success('添加成功', [], 1, 1);
} }
return $this->fail(UserFeedbackLogic::getError()); return $this->fail('添加失败');
} }
} }

View File

@ -30,8 +30,6 @@ class UserVisitController extends BaseApiController
if (true === $result) { if (true === $result) {
return $this->success('ok'); return $this->success('ok');
} }
return $this->fail(UserVisitLogic::getError());
} }
@ -54,7 +52,6 @@ class UserVisitController extends BaseApiController
if (true === $result) { if (true === $result) {
return $this->success('添加成功', [], 1, 1); return $this->success('添加成功', [], 1, 1);
} }
return $this->fail(UserVisitLogic::getError());
} }

View File

@ -38,9 +38,6 @@ class UserProductStorageController extends BaseApiController
$store_id=$params['store_id']; $store_id=$params['store_id'];
$times=$params['times']; $times=$params['times'];
UserProductStorageLogic::supply($info,$uid,$store_id,0,$times); UserProductStorageLogic::supply($info,$uid,$store_id,0,$times);
if(UserProductStorageLogic::hasError()){
return $this->fail(UserProductStorageLogic::getError());
}
return $this->success('操作成功'); return $this->success('操作成功');
} }
} }

View File

@ -31,10 +31,7 @@ class UserShipController extends BaseApiController
public function is_user_ship(){ public function is_user_ship(){
$data=$this->request->post(); $data=$this->request->post();
UserShipLogic::user_ship($data); UserShipLogic::user_ship($data);
if(UserShipLogic::hasError()){ return $this->success('ok');
return $this->fail(UserShipLogic::getError());
}else{
return $this->success('ok');
}
} }
} }

View File

@ -6,7 +6,7 @@ namespace app\api\lists\cate;
use app\admin\lists\BaseAdminDataLists; use app\admin\lists\BaseAdminDataLists;
use app\common\model\cate\Cate; use app\common\model\cate\Cate;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product\StoreProduct;
use app\Request; use app\Request;
use think\facade\Db; use think\facade\Db;
@ -28,7 +28,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['name', 'data', 'store_id', 'sort'], '=' => ['name', 'data', 'sort'],
]; ];
} }
@ -45,19 +45,23 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array public function lists(): array
{ {
$level = Request()->get('level', 1); $level = Request()->get('level', 1);
$source = Request()->get('source');
$pid = $this->request->get('pid',0); $pid = $this->request->get('pid',0);
// $this->searchWhere[] = ['stock', '>', 0]; // $this->searchWhere[] = ['stock', '>', 0];
$this->searchWhere[] = ['status', '=', 1]; $this->searchWhere[] = ['is_show', '=', 1];
if($source && $source==4){
$this->searchWhere[] = ['product_type', '=', 5];
}
if($pid && $level ==2){ if($pid && $level ==2){
$this->searchWhere[] = ['top_cate_id','=',$pid]; $this->searchWhere[] = ['top_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() $cate_arr = StoreProduct::where($this->searchWhere)->distinct()
->column('two_cate_id'); ->column('two_cate_id');
}elseif($pid && $level ==3){ }elseif($pid && $level ==3){
$this->searchWhere[] = ['two_cate_id','=',$pid]; $this->searchWhere[] = ['two_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() $cate_arr = StoreProduct::where($this->searchWhere)->distinct()
->column('cate_id'); ->column('cate_id');
}else{ }else{
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() $cate_arr = StoreProduct::where($this->searchWhere)->distinct()
->column('top_cate_id'); ->column('top_cate_id');
} }
$lists = []; $lists = [];
@ -85,14 +89,14 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
$pid = $this->request->get('pid',0); $pid = $this->request->get('pid',0);
if($pid && $level ==2){ if($pid && $level ==2){
$this->searchWhere[] = ['top_cate_id','=',$pid]; $this->searchWhere[] = ['top_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() $cate_arr = StoreProduct::where($this->searchWhere)->distinct()
->column('two_cate_id'); ->column('two_cate_id');
}elseif($pid && $level ==3){ }elseif($pid && $level ==3){
$this->searchWhere[] = ['two_cate_id','=',$pid]; $this->searchWhere[] = ['two_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() $cate_arr = StoreProduct::where($this->searchWhere)->distinct()
->column('cate_id'); ->column('cate_id');
}else{ }else{
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() $cate_arr = StoreProduct::where($this->searchWhere)->distinct()
->column('top_cate_id'); ->column('top_cate_id');
} }
return Cate::where('id', 'in', $cate_arr)->count(); return Cate::where('id', 'in', $cate_arr)->count();

View File

@ -9,7 +9,7 @@ use app\common\model\order\Cart;
use app\common\lists\ListsExtendInterface; use app\common\lists\ListsExtendInterface;
use app\common\model\Config; use app\common\model\Config;
use app\common\model\dict\DictType; use app\common\model\dict\DictType;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\user\User; use app\common\model\user\User;
@ -65,14 +65,14 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
->toArray(); ->toArray();
$off_activity = Config::where('name', 'off_activity')->value('value'); $off_activity = Config::where('name', 'off_activity')->value('value');
$user_ship = User::where('id', $userId)->value('user_ship'); $user_ship = User::where('id', $userId)->value('user_ship');
$field = 'product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id'; $field = 'id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch';
if (in_array($user_ship, [4, 6, 7])) { if (in_array($user_ship, [4, 6, 7])) {
$field = 'product_id,image,cost price,cost,store_name,unit,delete_time,vip_price,top_cate_id'; $field = 'id,id product_id,image,cost price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch';
} }
$this->user_ship = $user_ship; $this->user_ship = $user_ship;
$this->off_activity = $off_activity; $this->off_activity = $off_activity;
foreach ($list as $key => &$item) { foreach ($list as $key => &$item) {
$find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']]) $find = StoreProduct::where(['id' => $item['product_id']])
->field($field) ->field($field)
->find(); ->find();
if ($find) { if ($find) {
@ -84,6 +84,7 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
} }
$item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2); $item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2);
$this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2); $this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2);
$item['batch'] = $find['batch'];
$item['imgs'] = $find['image']; $item['imgs'] = $find['image'];
$item['price'] = $find['price']; $item['price'] = $find['price'];
$item['cost'] = $find['cost']; $item['cost'] = $find['cost'];

View File

@ -0,0 +1,109 @@
<?php
namespace app\api\lists\order;
use app\admin\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\order\Cart;
use app\common\lists\ListsExtendInterface;
use app\common\model\Config;
use app\common\model\dict\DictType;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\user\User;
/**
* 购物车列表
* Class RetailOrderList
* @package app\api\order
*/
class CartWholesaleList extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface
{
protected $total_price = 0;
protected $activity_price = 0;
protected $off_activity = 0;
protected $user_ship = 0;
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
*/
public function setSearch(): array
{
return ['='=>['store_id','source']];
}
/**
* @notes 购物车列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @date 2024/04/27 11:26
*/
public function lists($where = []): array
{
$userId = $this->request->userId;
if (!$userId) return [];
$where = [
'uid' => $userId,
'is_pay' => 0
];
$list = Cart::where($this->searchWhere)->where($where)
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
$field = 'id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch';
foreach ($list as $key => &$item) {
$find = StoreProduct::where(['id' => $item['product_id']])
->field($field)
->find();
if ($find) {
$item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2);
$this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2);
$item['batch'] = $find['batch'];
$item['imgs'] = $find['image'];
$item['price'] = $find['price'];
$item['cost'] = $find['cost'];
$item['goods_name'] = $find['store_name'];
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
}
}
return $list;
}
/**
* @notes 购物车数量
* @return int
* @date 2024/04/27 11:26
*/
public function count(): int
{
$userId = $this->request->userId;
if (!$userId) return 0;
$where = [
'uid' => $userId,
'is_pay' => 0
];
return Cart::where($this->searchWhere)->where($where)->count();
}
public function extend()
{
$data = [
'off_activity' => $this->off_activity,
'total_price' => $this->total_price,
'msg' => '',
'pay_price' => $this->total_price
];
return $data;
}
}

View File

@ -5,11 +5,8 @@ namespace app\api\lists\order;
use app\admin\lists\BaseAdminDataLists; use app\admin\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; 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 Picqer\Barcode\BarcodeGeneratorPNG; use Picqer\Barcode\BarcodeGeneratorPNG;
/** /**

View File

@ -6,11 +6,8 @@ namespace app\api\lists\product;
use app\api\lists\BaseApiDataLists; use app\api\lists\BaseApiDataLists;
use app\common\lists\ListsExtendInterface; use app\common\lists\ListsExtendInterface;
use app\common\lists\ListsSortInterface; use app\common\lists\ListsSortInterface;
use app\common\model\dict\DictType;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\cate\Cate;
use app\common\model\Config; use app\common\model\Config;
use app\common\model\user\User; use app\common\model\user\User;
//use app\common\model\goods\GoodsLabel; //use app\common\model\goods\GoodsLabel;
@ -35,7 +32,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['store_id', 'cate_id', 'top_cate_id', 'two_cate_id'], '=' => [ 'cate_id', 'top_cate_id', 'two_cate_id'],
'%pipe_like%' => ['store_name' => 'store_name|bar_code'], '%pipe_like%' => ['store_name' => 'store_name|bar_code'],
]; ];
} }
@ -58,7 +55,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
*/ */
public function setDefaultOrder(): array public function setDefaultOrder(): array
{ {
return ['price' => 'asc', 'id' => 'desc']; return ['sort'=>'desc','price' => 'asc', 'id' => 'desc'];
} }
/** /**
@ -72,6 +69,17 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
*/ */
public function lists(): array public function lists(): array
{ {
$store_name=$this->request->get('store_name');
if($store_name && $store_name!=''){
if (preg_match('/^1234-/',$store_name)) {
foreach($this->searchWhere as $k=>$v){
if($v[0]=='store_name|bar_code'){
unset($this->searchWhere[$k]);
$this->searchWhere[$k]=['bar_code','=',$store_name];
}
}
}
}
$order = $this->request->get('order', ''); $order = $this->request->get('order', '');
$field = $this->request->get('field', ''); $field = $this->request->get('field', '');
if (empty($order) || empty($field)) { if (empty($order) || empty($field)) {
@ -79,7 +87,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
} else { } else {
$order = [$field => $order]; $order = [$field => $order];
} }
$fields = 'id,product_id,top_cate_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; $fields = 'id,id product_id,top_cate_id,cate_id,store_name,cost,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock,is_lack';
$off_activity = Config::where('name', 'off_activity')->value('value'); $off_activity = Config::where('name', 'off_activity')->value('value');
if ($off_activity == 1) { if ($off_activity == 1) {
$tag = '赠10%品牌礼品券'; $tag = '赠10%品牌礼品券';
@ -96,13 +104,13 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
if ($uid > 0) { if ($uid > 0) {
$user_ship = User::where('id', $uid)->value('user_ship'); $user_ship = User::where('id', $uid)->value('user_ship');
if (in_array($user_ship, [4, 6, 7])) { if (in_array($user_ship, [4, 6, 7])) {
$fields = 'id,product_id,top_cate_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; $fields = 'id,id product_id,top_cate_id,cate_id,store_name,cost,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock,is_lack';
} }
} }
$this->off_activity = $off_activity; $this->off_activity = $off_activity;
$this->searchWhere[] = ['status', '=', 1]; $this->searchWhere[] = ['is_show', '=', 1];
// $this->searchWhere[] = ['stock', '>', 0]; // $this->searchWhere[] = ['stock', '>', 0];
return StoreBranchProduct::where($this->searchWhere) return StoreProduct::where($this->searchWhere)
->field($fields) ->field($fields)
->with(['className', 'unitName']) ->with(['className', 'unitName'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
@ -111,6 +119,9 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
if ($off_activity == 0 && $user_ship == 5 && $item['top_cate_id'] == 15189) { if ($off_activity == 0 && $user_ship == 5 && $item['top_cate_id'] == 15189) {
$item['price'] = $item['cost']; $item['price'] = $item['cost'];
} }
if($item['is_lack']==1){
$tag='缺货';
}
$item['tag'] = $tag; $item['tag'] = $tag;
return $item; return $item;
}) })
@ -126,7 +137,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
*/ */
public function count(): int public function count(): int
{ {
return StoreBranchProduct::where($this->searchWhere) return StoreProduct::where($this->searchWhere)
->count(); ->count();
} }
public function extend() public function extend()

View File

@ -0,0 +1,117 @@
<?php
namespace app\api\lists\product;
use app\api\lists\BaseApiDataLists;
use app\common\lists\ListsExtendInterface;
use app\common\lists\ListsSortInterface;
use app\common\model\store_product\StoreProduct;
use app\common\lists\ListsSearchInterface;
use app\common\model\Config;
use app\common\model\user\User;
//use app\common\model\goods\GoodsLabel;
use think\facade\Db;
/**
* 商品列表列表
* Class goods
* @package app\api\goods
*/
class ProductWholesaleLists extends BaseApiDataLists implements ListsSearchInterface, ListsSortInterface, ListsExtendInterface
{
protected $off_activity = 0;
protected $user_ship = 0;
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/04/23 11:28
*/
public function setSearch(): array
{
return [
'=' => [ 'cate_id', 'top_cate_id', 'two_cate_id'],
'%pipe_like%' => ['store_name' => 'store_name|bar_code'],
];
}
/**
* @notes 设置支持排序字段
* @return string[]
* @date 2021/12/29 10:07
* @remark 格式: ['前端传过来的字段名' => '数据库中的字段名'];
*/
public function setSortFields(): array
{
return ['sell' => 'price', 'sales' => 'sales',];
}
/**
* @notes 设置默认排序
* @return string[]
* @date 2021/12/29 10:06
*/
public function setDefaultOrder(): array
{
return ['price' => 'asc', 'id' => 'desc'];
}
/**
* @notes 获取商品列表列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/04/23 11:28
*/
public function lists(): array
{
$order = $this->request->get('order', '');
$field = $this->request->get('field', '');
if (empty($order) || empty($field)) {
$order = $this->sortOrder;
} else {
$order = [$field => $order];
}
$fields = 'id,id product_id,top_cate_id,cate_id,store_name,cost,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
$this->searchWhere[] = ['is_show', '=', 1];
$this->searchWhere[] = ['product_type', '=', 5];
// $this->searchWhere[] = ['stock', '>', 0];
return StoreProduct::where($this->searchWhere)
->field($fields)
->with(['className', 'unitName'])
->limit($this->limitOffset, $this->limitLength)
->order($order)
->select()
->toArray();
}
/**
* @notes 获取商品列表数量
* @return int
* @author likeadmin
* @date 2024/04/23 11:28
*/
public function count(): int
{
return StoreProduct::where($this->searchWhere)
->count();
}
public function extend()
{
$price = 'price';
$op_price = 'price';
$data = [
'off_activity' => $this->off_activity,
'price' => $price,
'op_price' => $op_price,
];
return $data;
}
}

View File

@ -7,7 +7,6 @@ use app\api\lists\BaseApiDataLists;
use app\common\lists\ListsExtendInterface; use app\common\lists\ListsExtendInterface;
use app\common\lists\ListsSortInterface; use app\common\lists\ListsSortInterface;
use app\common\model\dict\DictType; use app\common\model\dict\DictType;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\cate\Cate; use app\common\model\cate\Cate;
@ -72,22 +71,17 @@ class StoreProductLists extends BaseApiDataLists implements ListsSearchInterface
*/ */
public function lists(): array public function lists(): array
{ {
$store_id= $this->request->__get('store_id'); $fields = 'id,id product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
if($store_id){
$this->searchWhere[] = ['store_id', '=', $store_id];
}
$fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
$type=$this->request->get('type',0); $type=$this->request->get('type',0);
if($type==1){ if($type==1){
$fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; $fields = 'id,id product_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
}elseif($type==2){ }elseif($type==2){
$fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,purchase price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; $fields = 'id,id product_id,cate_id,store_name,cost,store_id,vip_price,purchase,purchase price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
} }
$this->searchWhere[] = ['status', '=', 1]; $this->searchWhere[] = ['status', '=', 1];
// $this->searchWhere[] = ['stock', '>', 0]; // $this->searchWhere[] = ['stock', '>', 0];
return StoreBranchProduct::where($this->searchWhere) return StoreProduct::where($this->searchWhere)
->field($fields) ->field($fields)
->with(['className', 'unitName']) ->with(['className', 'unitName'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
@ -105,7 +99,7 @@ class StoreProductLists extends BaseApiDataLists implements ListsSearchInterface
*/ */
public function count(): int public function count(): int
{ {
return StoreBranchProduct::where($this->searchWhere) return StoreProduct::where($this->searchWhere)
->count(); ->count();
} }
} }

View File

@ -48,62 +48,76 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac
*/ */
public function lists(): array public function lists(): array
{ {
$latitude = $this->request->get('latitude',''); $latitude = $this->request->get('latitude', '');
$longitude = $this->request->get('longitude',''); $longitude = $this->request->get('longitude', '');
$cart_id = $this->request->get('cart_id',''); $cart_id = $this->request->get('cart_id', '');
// if(empty($longitude) || empty($latitude)){ // if(empty($longitude) || empty($latitude)){
// throw new Exception('缺失经纬度'); // throw new Exception('缺失经纬度');
// } // }
$where[]=['is_show','=',YesNoEnum::YES]; $where[] = ['is_show', '=', YesNoEnum::YES];
$data = SystemStore::where($this->searchWhere)->where($where) $data = SystemStore::where($this->searchWhere)->where($where)
->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show', ->field([
'day_time','is_store','latitude','longitude','day_start','day_end','is_store' 'id',
,'is_send','abbreviation' 'name',
'phone',
'detailed_address',
'image',
'is_show',
'day_time',
'is_store',
'latitude',
'longitude',
'day_start',
'day_end',
'is_store',
'is_send',
'abbreviation'
]) ])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select() ->select()
->toArray(); ->toArray();
if($cart_id){ if ($cart_id) {
if($latitude && $longitude){ if ($latitude && $longitude) {
$cart_id = explode(',',$cart_id); foreach ($data as &$values) {
$cart_select = Cart::whereIn('id', $cart_id) $values['distance'] = haversineDistance($values['latitude'], $values['longitude'], $latitude, $longitude);
->field('id,product_id,cart_num,store_id')->select()->toArray(); $values['reservation'] = 1;
foreach ($cart_select as $v) {
foreach ($data as &$values){
$store = StoreBranchProduct::where([
'store_id'=>$values['id'],
'product_id'=>$v['product_id'],
])->field('id,store_name,stock')->withTrashed()->find();
if(empty($store)){
$store['stock'] =0;
}
$values['reservation'] = 0;
if($store['stock'] < $v['cart_num']){
$values['reservation'] = 1;
}
$values['distance'] = haversineDistance($values['latitude'],$values['longitude'],$latitude,$longitude);
}
} }
}else{
foreach ($data as &$values){ // $cart_id = explode(',',$cart_id);
// $cart_select = Cart::whereIn('id', $cart_id)
// ->field('id,product_id,cart_num,store_id')->select()->toArray();
// foreach ($cart_select as $v) {
// foreach ($data as &$values){
// $store = StoreBranchProduct::where([
// 'store_id'=>$values['id'],
// 'product_id'=>$v['product_id'],
// ])->field('id,store_name,stock')->withTrashed()->find();
// if(empty($store)){
// $store['stock'] =0;
// }
// $values['reservation'] = 0;
// if($store['stock'] < $v['cart_num']){
// }
// }
// }
} else {
foreach ($data as &$values) {
$values['distance'] = 0; $values['distance'] = 0;
} }
} }
} else {
}else{ if ($latitude && $longitude) {
if($latitude && $longitude){ foreach ($data as &$value) {
foreach ($data as &$value){ $value['distance'] = haversineDistance($value['latitude'], $value['longitude'], $latitude, $longitude);
$value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$latitude,$longitude);
} }
}else{ } else {
foreach ($data as &$values){ foreach ($data as &$values) {
$values['distance'] = 0; $values['distance'] = 0;
} }
} }
} }
usort($data, function ($a, $b) { usort($data, function ($a, $b) {
@ -121,8 +135,7 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac
*/ */
public function count(): int public function count(): int
{ {
$where[]=['is_show','=',YesNoEnum::YES]; $where[] = ['is_show', '=', YesNoEnum::YES];
return SystemStore::where($this->searchWhere)->where($where)->count(); return SystemStore::where($this->searchWhere)->where($where)->count();
} }
}
}

View File

@ -27,7 +27,7 @@ use app\common\service\{
}; };
use app\common\model\user\{User, UserAuth}; use app\common\model\user\{User, UserAuth};
use app\common\service\wechat\WeChatMnpService; use app\common\service\wechat\WeChatMnpService;
use support\exception\BusinessException;
use Webman\Config; use Webman\Config;
/** /**
@ -63,8 +63,7 @@ class LoginLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -88,7 +87,7 @@ class LoginLogic extends BaseLogic
$user = User::where($where)->findOrEmpty(); $user = User::where($where)->findOrEmpty();
if ($user->isEmpty()) { if ($user->isEmpty()) {
throw new \Exception('用户不存在'); throw new BusinessException('用户不存在');
} }
//更新登录信息 //更新登录信息
@ -121,8 +120,7 @@ class LoginLogic extends BaseLogic
'share_name' => $share_name.'No.'.preg_replace('/4/','*', $user['id']), 'share_name' => $share_name.'No.'.preg_replace('/4/','*', $user['id']),
]; ];
} catch (\Exception $e) { } catch (\Exception $e) {
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -214,9 +212,8 @@ class LoginLogic extends BaseLogic
} }
return $userInfo; return $userInfo;
} catch (\Exception $e) { } catch (\Throwable $e) {
self::$error = $e->getMessage(); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -242,9 +239,8 @@ class LoginLogic extends BaseLogic
// Db::commit(); // Db::commit();
return $userInfo; return $userInfo;
} catch (\Exception $e) { } catch (\Exception $e) {
throw new BusinessException($e->getMessage());
// Db::rollback(); // Db::rollback();
self::$error = $e->getMessage();
return false;
} }
} }
@ -260,7 +256,7 @@ class LoginLogic extends BaseLogic
{ {
$user = User::findOrEmpty($userId); $user = User::findOrEmpty($userId);
if ($user->isEmpty()) { if ($user->isEmpty()) {
throw new \Exception('用户不存在'); throw new BusinessException('用户不存在');
} }
$time = time(); $time = time();
@ -348,7 +344,7 @@ class LoginLogic extends BaseLogic
//先检查openid是否有记录 //先检查openid是否有记录
$isAuth = UserAuth::where('openid', '=', $response['openid'])->findOrEmpty(); $isAuth = UserAuth::where('openid', '=', $response['openid'])->findOrEmpty();
if (!$isAuth->isEmpty()) { if (!$isAuth->isEmpty()) {
throw new \Exception('该微信已被绑定'); throw new BusinessException('该微信已被绑定');
} }
if (isset($response['unionid']) && !empty($response['unionid'])) { if (isset($response['unionid']) && !empty($response['unionid'])) {
@ -356,7 +352,7 @@ class LoginLogic extends BaseLogic
$userAuth = UserAuth::where(['unionid' => $response['unionid']]) $userAuth = UserAuth::where(['unionid' => $response['unionid']])
->findOrEmpty(); ->findOrEmpty();
if (!$userAuth->isEmpty() && $userAuth->user_id != $response['user_id']) { if (!$userAuth->isEmpty() && $userAuth->user_id != $response['user_id']) {
throw new \Exception('该微信已被绑定'); throw new BusinessException('该微信已被绑定');
} }
} }
@ -456,8 +452,7 @@ class LoginLogic extends BaseLogic
if($find){ if($find){
$auth=UserAuth::where(['user_id'=>$find['id']])->find();//别人的 $auth=UserAuth::where(['user_id'=>$find['id']])->find();//别人的
if($auth){ if($auth){
self::$error ='该手机号已绑定'; throw new BusinessException('该手机号已绑定');
return false;
}else{ }else{
UserAuth::where(['user_id'=>$userId])->update(['user_id'=>$find['id']]); UserAuth::where(['user_id'=>$userId])->update(['user_id'=>$find['id']]);
} }

View File

@ -6,6 +6,7 @@ namespace app\api\logic\order;
use app\common\model\order\Cart; use app\common\model\order\Cart;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\store_product_log\StoreProductLog; use app\common\model\store_product_log\StoreProductLog;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -27,10 +28,10 @@ class CartLogic extends BaseLogic
*/ */
public static function add(array $params) public static function add(array $params)
{ {
if ($params['store_id'] <= 0) { if ($params['store_id'] < 0) {
self::setError('门店ID不能为空'); throw new BusinessException('门店ID不能为空');
return false;
} }
$source=$params['source'] ?? 0;
Db::startTrans(); Db::startTrans();
try { try {
//check //check
@ -38,7 +39,8 @@ class CartLogic extends BaseLogic
'uid' => $params['uid'], 'uid' => $params['uid'],
'store_id' => $params['store_id'], 'store_id' => $params['store_id'],
'product_id' => $params['product_id'], 'product_id' => $params['product_id'],
'is_pay' => 0 'is_pay' => 0,
'source' => $source,
])->field('id')->find(); ])->field('id')->find();
if ($check) { if ($check) {
Cart::where('id', $check['id'])->inc('cart_num', $params['cart_num']) Cart::where('id', $check['id'])->inc('cart_num', $params['cart_num'])
@ -53,6 +55,7 @@ class CartLogic extends BaseLogic
'staff_id' => $params['staff_id'] ?? 0, 'staff_id' => $params['staff_id'] ?? 0,
'cart_num' => $params['cart_num'], 'cart_num' => $params['cart_num'],
'is_new' => $params['is_new'] ?? 0, 'is_new' => $params['is_new'] ?? 0,
'source' =>$source,
]); ]);
} }
StoreProductLog::create([ StoreProductLog::create([
@ -66,10 +69,9 @@ class CartLogic extends BaseLogic
]); ]);
Db::commit(); Db::commit();
return $cart; return $cart;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -85,18 +87,24 @@ class CartLogic extends BaseLogic
{ {
Db::startTrans(); Db::startTrans();
try { try {
Cart::where([ if(isset($params['type']) && $params['type']=='inc'){
'uid' => $params['uid'], Cart::where([
'store_id' => $params['store_id'], 'uid' => $params['uid'],
'product_id' => $params['product_id'] 'store_id' => $params['store_id'],
]) 'product_id' => $params['product_id']
->update(['cart_num' => $params['cart_num']]); ])->inc('cart_num')->update();
}else{
Cart::where([
'uid' => $params['uid'],
'store_id' => $params['store_id'],
'product_id' => $params['product_id']
])->update(['cart_num' => $params['cart_num']]);
}
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -66,16 +66,17 @@ class OrderLogic extends BaseLogic
*/ */
static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = [], $createOrder = 0) static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = [], $createOrder = 0)
{ {
if(empty($params['store_id']) || $params['store_id'] <= 0){ if (empty($params['store_id']) || $params['store_id'] <= 0) {
self::setError('请选择门店'); throw new BusinessException('请选择门店');
return false; }
$source=0;
if (isset($params['source']) && $params['source'] >0) {
$source=$params['source'];
} }
$where = ['is_pay' => 0]; $where = ['is_pay' => 0];
$cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray(); $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num,source')->select()->toArray();
if (empty($cart_select)) { if (empty($cart_select)) {
self::setError('购物车为空'); throw new BusinessException('购物车为空');
return false;
} }
try { try {
self::$total_price = 0; self::$total_price = 0;
@ -89,18 +90,21 @@ class OrderLogic extends BaseLogic
self::$fresh_price = 0; //生鲜金额 self::$fresh_price = 0; //生鲜金额
/** 计算价格 */ /** 计算价格 */
$off_activity = Config::where('name', 'off_activity')->value('value'); $off_activity = Config::where('name', 'off_activity')->value('value');
$field = 'product_id id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose'; $field = 'id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose';
foreach ($cart_select as $k => $v) { foreach ($cart_select as $k => $v) {
$find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field($field)->find(); if ($source == 2) {
$field = 'product_id,product_id id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose';
$find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->find();
} else {
$find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find();
}
if (!$find) { if (!$find) {
self::setError('商品不存在'); throw new BusinessException('商品不存在');
return false;
} }
if (convertNumber($v['cart_num']) == false) { if (convertNumber($v['cart_num']) == false) {
$is_bulk = StoreProductUnit::where('id', $find['unit'])->value('is_bulk'); $is_bulk = StoreProductUnit::where('id', $find['unit'])->value('is_bulk');
if ($is_bulk == 0) { if ($is_bulk == 0) {
self::setError('非计量商品,不能有小数,请编辑购物车'); throw new BusinessException('非计量商品,不能有小数,请编辑购物车');
return false;
} }
} }
$StoreCategory = StoreCategory::where('id', $find['cate_id'])->find(); $StoreCategory = StoreCategory::where('id', $find['cate_id'])->find();
@ -115,21 +119,26 @@ class OrderLogic extends BaseLogic
} }
unset($cart_select[$k]['id']); unset($cart_select[$k]['id']);
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
if ($off_activity == 1 || ($user != null && in_array($user['user_ship'], [4, 6, 7]))) { if ($v['source'] != 4) {
$price = $find['cost']; if ($off_activity == 1 || ($user != null && in_array($user['user_ship'], [4, 6, 7]))) {
} else { $price = $find['cost'];
$price = $find['price']; } else {
//单门店活动判断 $price = $find['price'];
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 ($params['store_id'] == getenv('ACTIVITY_STORE_ID')) {
if ($storeBranchPrice) { $storeBranchPrice = StoreBranchProduct::where('store_id', getenv('ACTIVITY_STORE_ID'))->where('product_id', $v['product_id'])->value('price');
$price = $storeBranchPrice; if ($storeBranchPrice) {
$price = $storeBranchPrice;
}
} }
} }
if ($off_activity == 0 && $find['top_cate_id'] == 15189 && $user && $user['user_ship'] == 5) {
$price = $find['cost'];
}
} else {
$price = $find['price'];
} }
if ($off_activity == 0 && $find['top_cate_id'] == 15189 && $user && $user['user_ship'] == 5) {
$price = $find['cost'];
}
$cart_select[$k]['price'] = $price; $cart_select[$k]['price'] = $price;
$cart_select[$k]['cost'] = $find['cost']; $cart_select[$k]['cost'] = $find['cost'];
$cart_select[$k]['vip'] = 0; $cart_select[$k]['vip'] = 0;
@ -172,6 +181,7 @@ class OrderLogic extends BaseLogic
$cart_select[$k]['imgs'] = $find['image']; $cart_select[$k]['imgs'] = $find['image'];
$cart_select[$k]['store_id'] = $params['store_id'] ?? 0; $cart_select[$k]['store_id'] = $params['store_id'] ?? 0;
$cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name'); $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::$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); self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2);
self::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2); self::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2);
@ -193,12 +203,11 @@ class OrderLogic extends BaseLogic
$pay_price = self::$pay_price; // bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 $pay_price = self::$pay_price; // bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
//判断生鲜是否大于200 //判断生鲜是否大于200
if ($createOrder == 1 && self::$fresh_price > 0) { // if ($createOrder == 1 && self::$fresh_price > 0 &&$source!=2) {
if (self::$pay_price < 200) { // if (self::$pay_price < 200) {
self::setError('订单包含生鲜产品订单金额必须大于200元才能下单'); // throw new BusinessException('订单包含生鲜产品订单金额必须大于200元才能下单');
return false; // }
} // }
}
if (isset($params['store_id']) && $params['store_id'] == getenv('ACTIVITY_STORE_ID')) { if (isset($params['store_id']) && $params['store_id'] == getenv('ACTIVITY_STORE_ID')) {
$off_activity = 1; $off_activity = 1;
} }
@ -222,7 +231,7 @@ class OrderLogic extends BaseLogic
'activities' => $off_activity, 'activities' => $off_activity,
'deduction_price' => self::$deduction_price, //抵扣金额 'deduction_price' => self::$deduction_price, //抵扣金额
'frozen_money' => 0, //self::$frozen_money, //返还金额(活动关闭得时候有) 'frozen_money' => 0, //self::$frozen_money, //返还金额(活动关闭得时候有)
'source' => 0, 'source' => $source,
'is_storage' => $params['is_storage'] ?? 0, 'is_storage' => $params['is_storage'] ?? 0,
'address_id' => 0, 'address_id' => 0,
]; ];
@ -230,9 +239,6 @@ class OrderLogic extends BaseLogic
if ($params['store_id']) { if ($params['store_id']) {
$order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send'); $order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send');
} }
if (isset($params['source']) && $params['source'] > 0) {
$order['source'] = $params['source'];
}
if (isset($params['store_id']) && $params['store_id'] > 0) { if (isset($params['store_id']) && $params['store_id'] > 0) {
$store_id = $params['store_id']; $store_id = $params['store_id'];
@ -256,10 +262,8 @@ class OrderLogic extends BaseLogic
$currentDate = date('Y-m-d'); $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) { } catch (\Throwable $e) {
d($e); throw new BusinessException($e->getMessage());
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];
} }
@ -276,17 +280,10 @@ class OrderLogic extends BaseLogic
$params['order_id'] = $order_id; $params['order_id'] = $order_id;
$params['verify_code'] = $verify_code; $params['verify_code'] = $verify_code;
$orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params, 1); $orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params, 1);
if ($orderInfo == false) {
self::setError(self::getError());
return false;
}
if (!$orderInfo) {
return false;
}
$uid = $user['id'] ?? 0; $uid = $user['id'] ?? 0;
$_order = $orderInfo['order']; $_order = $orderInfo['order'];
if ($_order['pay_price'] == 0) { if ($_order['pay_price'] == 0) {
throw new \Exception('支付金额不能为0'); throw new BusinessException('支付金额不能为0');
} }
$_order['uid'] = $uid; $_order['uid'] = $uid;
$_order['spread_uid'] = $params['spread_uid'] ?? 0; $_order['spread_uid'] = $params['spread_uid'] ?? 0;
@ -305,8 +302,6 @@ class OrderLogic extends BaseLogic
if ($uid > 0) { if ($uid > 0) {
$address = UserAddress::where(['uid' => $uid])->find(); $address = UserAddress::where(['uid' => $uid])->find();
if ($address) { if ($address) {
$_order['real_name'] = $address['real_name'];
$_order['user_phone'] = $address['phone'];
if ($address['area']) { if ($address['area']) {
$_order['user_address'] = Db::name('geo_area')->where('area_code', $address['area'])->value('area_name') ?? ''; $_order['user_address'] = Db::name('geo_area')->where('area_code', $address['area'])->value('area_name') ?? '';
} }
@ -327,7 +322,7 @@ class OrderLogic extends BaseLogic
$_order['status'] = 1; $_order['status'] = 1;
} }
if ($_order['pay_type'] == PayEnum::BALANCE_PAY && $user != null && $user['now_money'] < $_order['pay_price']) { if ($_order['pay_type'] == PayEnum::BALANCE_PAY && $user != null && $user['now_money'] < $_order['pay_price']) {
throw new \Exception('余额不足'); throw new BusinessException('余额不足');
} }
//生成核销码 //生成核销码
// $generator = new BarcodeGeneratorPNG(); // $generator = new BarcodeGeneratorPNG();
@ -341,7 +336,7 @@ class OrderLogic extends BaseLogic
$order = StoreOrder::create($_order); $order = StoreOrder::create($_order);
$goods_list = $orderInfo['cart_list']; $goods_list = $orderInfo['cart_list'];
foreach ($goods_list as $k => $v) { foreach ($goods_list as $k => $v) {
$goods_list[$k]['oid'] = $order->id; $goods_list[$k]['oid'] = $order->id;
$goods_list[$k]['uid'] = $uid; $goods_list[$k]['uid'] = $uid;
@ -356,8 +351,7 @@ class OrderLogic extends BaseLogic
return $order; return $order;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -378,8 +372,7 @@ class OrderLogic extends BaseLogic
$cart_select = Cart::whereIn('id', $params['cart_id']) $cart_select = Cart::whereIn('id', $params['cart_id'])
->where($where)->field('id,product_id,cart_num,store_id')->select()->toArray(); ->where($where)->field('id,product_id,cart_num,store_id')->select()->toArray();
if (empty($cart_select)) { if (empty($cart_select)) {
self::setError('购物车为空'); throw new BusinessException('购物车为空');
return false;
} }
$newArr = []; $newArr = [];
//检查购物车对比店铺得商品数量差异 //检查购物车对比店铺得商品数量差异
@ -447,12 +440,11 @@ class OrderLogic extends BaseLogic
// 提交事务 // 提交事务
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
// 回滚事务 // 回滚事务
Db::rollback(); Db::rollback();
Log::error('支付失败' . $e->getMessage() . '。like:' . $e->getLine()); Log::error('支付失败' . $e->getMessage() . '。like:' . $e->getLine());
self::setError('支付失败' . $e->getMessage()); throw new BusinessException('支付失败' . $e->getMessage());
return false;
} }
} }
@ -467,11 +459,10 @@ class OrderLogic extends BaseLogic
return []; return [];
} }
$goods_arr = array_unique($goods_id); $goods_arr = array_unique($goods_id);
$select = StoreBranchProduct::where('product_id', 'in', $goods_arr)->with('unitName')->field('id,store_name,price,image,unit')->select(); $select = StoreProduct::where('id', 'in', $goods_arr)->with('unitName')->field('id,store_name,price,image,unit')->select();
return $select->toArray(); return $select->toArray();
} catch (\Exception $e) { } catch (\Throwable $e) {
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -487,9 +478,6 @@ class OrderLogic extends BaseLogic
$data[$k]['store_id'] = $v['store_id']; $data[$k]['store_id'] = $v['store_id'];
$data[$k]['staff_id'] = $v['staff_id']; $data[$k]['staff_id'] = $v['staff_id'];
$data[$k]['combination_id'] = 0; $data[$k]['combination_id'] = 0;
$data[$k]['seckill_id'] = 0;
$data[$k]['bargain_id'] = 0;
$data[$k]['discount_id'] = 0;
$data[$k]['status'] = 1; $data[$k]['status'] = 1;
$data[$k]['staff_id'] = 0; $data[$k]['staff_id'] = 0;
$data[$k]['is_new'] = 0; $data[$k]['is_new'] = 0;
@ -511,10 +499,8 @@ class OrderLogic extends BaseLogic
$find['goods_list'] = StoreOrderCartInfo::where('oid', $find['id']) $find['goods_list'] = StoreOrderCartInfo::where('oid', $find['id'])
->field('product_id,cart_num nums,store_id')->select()->each(function ($item) use ($find) { ->field('product_id,cart_num nums,store_id')->select()->each(function ($item) use ($find) {
$find = StoreBranchProduct::where('product_id', $item['product_id'])->where('store_id', $find['store_id'])->find(); $find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find();
if (empty($find)) {
$find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find();
}
$item['store_name'] = $find['store_name']; $item['store_name'] = $find['store_name'];
$item['nums'] = floatval($item['nums']); $item['nums'] = floatval($item['nums']);
$item['image'] = $find['image']; $item['image'] = $find['image'];
@ -584,8 +570,7 @@ class OrderLogic extends BaseLogic
'verify_code' => $params['verify_code'] 'verify_code' => $params['verify_code']
])->find(); ])->find();
if (empty($order)) { if (empty($order)) {
self::setError('订单不存在'); throw new BusinessException('订单不存在');
return false;
} }
Db::startTrans(); Db::startTrans();
try { try {
@ -631,10 +616,9 @@ class OrderLogic extends BaseLogic
} }
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -643,7 +627,7 @@ class OrderLogic extends BaseLogic
{ {
$store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id'); $store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id');
if (empty($store_id)) { if (empty($store_id)) {
throw new \Exception('该用户未绑定店铺请查看'); throw new BusinessException('该用户未绑定店铺请查看');
} }
$query = StoreOrderCartInfo::alias('o') $query = StoreOrderCartInfo::alias('o')
->leftJoin('store_branch_product p', 'p.id = o.product_id') ->leftJoin('store_branch_product p', 'p.id = o.product_id')
@ -693,7 +677,7 @@ class OrderLogic extends BaseLogic
$store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id'); $store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id');
if (empty($store_id)) { if (empty($store_id)) {
throw new \Exception('该用户未绑定店铺请查看'); throw new BusinessException('该用户未绑定店铺请查看');
} }
//先查商品相似 //先查商品相似
@ -785,7 +769,7 @@ class OrderLogic extends BaseLogic
self::dealChangeCartInfo($refundOrder); self::dealChangeCartInfo($refundOrder);
// d($leftOrder,$refundOrder); // d($leftOrder,$refundOrder);
Db::commit(); Db::commit();
} catch (\Exception $e) { } catch (\Throwable $e) {
// 回滚事务 // 回滚事务
Db::rollback(); Db::rollback();
throw new BusinessException($e->getMessage()); throw new BusinessException($e->getMessage());

View File

@ -4,6 +4,7 @@ namespace app\api\logic\user;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\user\UserAddress; use app\common\model\user\UserAddress;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
/** /**
@ -48,10 +49,9 @@ class AddressLogic extends BaseLogic
]); ]);
Db::commit(); Db::commit();
return $id; return $id;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -95,10 +95,9 @@ class AddressLogic extends BaseLogic
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }

View File

@ -4,7 +4,8 @@
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\user\UserFeedback; use app\common\model\user\UserFeedback;
use think\facade\Db; use support\exception\BusinessException;
use think\facade\Db;
class UserFeedbackLogic extends BaseLogic class UserFeedbackLogic extends BaseLogic
{ {
@ -29,10 +30,10 @@
]); ]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
} }

View File

@ -24,6 +24,7 @@ use app\common\{logic\BaseLogic,
use app\common\logic\UserSignLogic; use app\common\logic\UserSignLogic;
use app\common\model\user_label\UserLabel; use app\common\model\user_label\UserLabel;
use support\Cache; use support\Cache;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -49,7 +50,7 @@ class UserLogic extends BaseLogic
$response = (new WeChatMnpService())->getUserPhoneNumber($params['code']); $response = (new WeChatMnpService())->getUserPhoneNumber($params['code']);
$phoneNumber = $response['phone_info']['purePhoneNumber'] ?? ''; $phoneNumber = $response['phone_info']['purePhoneNumber'] ?? '';
if (empty($phoneNumber)) { if (empty($phoneNumber)) {
throw new \Exception('获取手机号码失败'); throw new BusinessException('获取手机号码失败');
} }
$user = User::where([ $user = User::where([
@ -75,9 +76,8 @@ class UserLogic extends BaseLogic
]); ]);
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -211,7 +211,7 @@ class UserLogic extends BaseLogic
$code = generateRandomCode(); $code = generateRandomCode();
$phone = User::where('id',$uid)->value('mobile'); $phone = User::where('id',$uid)->value('mobile');
if(empty($phone)){ if(empty($phone)){
throw new \Exception('用户未设置手机号'); throw new BusinessException('用户未设置手机号');
} }
$template = getenv('SMS_TEMPLATE'); $template = getenv('SMS_TEMPLATE');
$check =(new SmsService())->client($phone,$template,$code); $check =(new SmsService())->client($phone,$template,$code);

View File

@ -5,7 +5,8 @@
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\store_visit\StoreVisit; use app\common\model\store_visit\StoreVisit;
use app\common\model\user\UserVisit; use app\common\model\user\UserVisit;
use think\facade\Db; use support\Log;
use think\facade\Db;
class UserVisitLogic extends BaseLogic class UserVisitLogic extends BaseLogic
{ {
@ -39,10 +40,9 @@
} }
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); Log::error('添加商品浏览失败:'.$e->getMessage());
return false;
} }
} }
@ -70,10 +70,9 @@
} }
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); Log::error('添加用户访问失败:'.$e->getMessage());
return false;
} }

View File

@ -13,6 +13,7 @@ use app\common\service\sms\SmsDriver;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
use app\common\model\user\User; use app\common\model\user\User;
use support\Cache; use support\Cache;
use support\exception\BusinessException;
use think\Exception; use think\Exception;
use Webman\Config; use Webman\Config;
/** /**
@ -92,7 +93,7 @@ class LoginAccountValidate extends BaseValidate
//账号安全机制,连续输错后锁定,防止账号密码暴力破解 //账号安全机制,连续输错后锁定,防止账号密码暴力破解
$userAccountSafeCache = new UserAccountSafeCache(); $userAccountSafeCache = new UserAccountSafeCache();
if (!$userAccountSafeCache->isSafe()) { if (!$userAccountSafeCache->isSafe()) {
return '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试'; throw new BusinessException( '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试');
} }
$where = []; $where = [];
@ -106,22 +107,22 @@ class LoginAccountValidate extends BaseValidate
->findOrEmpty(); ->findOrEmpty();
if ($userInfo->isEmpty()) { if ($userInfo->isEmpty()) {
return '用户不存在'; throw new BusinessException( '用户不存在');
} }
if ($userInfo['is_disable'] === YesNoEnum::YES) { if ($userInfo['is_disable'] === YesNoEnum::YES) {
return '用户已禁用'; throw new BusinessException( '用户已禁用');
} }
if (empty($userInfo['password'])) { if (empty($userInfo['password'])) {
$userAccountSafeCache->record(); $userAccountSafeCache->record();
return '用户不存在'; throw new BusinessException( '用户不存在');
} }
$passwordSalt = Config::get('project.unique_identification'); $passwordSalt = Config::get('project.unique_identification');
if ($userInfo['password'] !== create_password($password, $passwordSalt)) { if ($userInfo['password'] !== create_password($password, $passwordSalt)) {
$userAccountSafeCache->record(); $userAccountSafeCache->record();
return '密码错误'; throw new BusinessException( '密码错误');
} }
$userAccountSafeCache->relieve(); $userAccountSafeCache->relieve();
@ -147,10 +148,10 @@ class LoginAccountValidate extends BaseValidate
} }
$code = Cache::get($remark); $code = Cache::get($remark);
if(empty($code)){ if(empty($code)){
return '验证码不存在'; throw new BusinessException( '验证码不存在');
} }
if (isset($data['code']) && $code != $data['code']) { if (isset($data['code']) && $code != $data['code']) {
return '验证码错误'; throw new BusinessException( '验证码错误');
} }
return true; return true;

View File

@ -100,7 +100,7 @@ class CapitalFlowLogic extends BaseLogic
* @param $mark * @param $mark
* @return mixed * @return mixed
*/ */
public function storeIncome($category, $linkType, $linkId, $amount, $mark = '') public function storeIncome($category, $linkType, $linkId, $amount, $mark = '',$key='')
{ {
$model = new CapitalFlow(); $model = new CapitalFlow();
$model->store_id = $this->store['id']; $model->store_id = $this->store['id'];
@ -108,8 +108,8 @@ class CapitalFlowLogic extends BaseLogic
$model->link_type = $linkType; $model->link_type = $linkType;
$model->link_id = $linkId; $model->link_id = $linkId;
$model->amount = $amount; $model->amount = $amount;
$model->before_balance = $this->store['balance']; $model->before_balance = $this->store[$key]??0;
$model->balance = bcadd($this->store['balance'], $amount, 2); $model->balance = bcadd($this->store[$key]??0, $amount, 2);
$model->create_time = date('Y-m-d H:i:s'); $model->create_time = date('Y-m-d H:i:s');
$model->type = 'in'; $model->type = 'in';
$model->title = $this->getTitle($category, $amount); $model->title = $this->getTitle($category, $amount);
@ -129,7 +129,7 @@ class CapitalFlowLogic extends BaseLogic
* @param $mark * @param $mark
* @return mixed * @return mixed
*/ */
public function storeExpense($category, $linkType, $linkId, $amount, $mark = '') public function storeExpense($category, $linkType, $linkId, $amount, $mark = '',$key='')
{ {
$model = new CapitalFlow(); $model = new CapitalFlow();
$model->store_id = $this->store['store_id']; $model->store_id = $this->store['store_id'];
@ -138,8 +138,8 @@ class CapitalFlowLogic extends BaseLogic
$model->link_type = $linkType; $model->link_type = $linkType;
$model->link_id = $linkId; $model->link_id = $linkId;
$model->amount = $amount; $model->amount = $amount;
$model->before_balance = $this->store['balance']; $model->before_balance = $this->store[$key]??0;
$model->balance = bcsub($this->store['balance'], $amount, 2); $model->balance = bcsub($this->store[$key], $amount, 2);
$model->create_time = date('Y-m-d H:i:s'); $model->create_time = date('Y-m-d H:i:s');
$model->type = 'out'; $model->type = 'out';
$model->title = $this->getTitle($category, $amount); $model->title = $this->getTitle($category, $amount);
@ -166,6 +166,7 @@ class CapitalFlowLogic extends BaseLogic
case 'store_order_refund': case 'store_order_refund':
return "店铺订单退款{$amount}"; return "店铺订单退款{$amount}";
case 'store_margin_refund': case 'store_margin_refund':
case 'store_paid_deposit_refund':
return "店铺退还保证金{$amount}"; return "店铺退还保证金{$amount}";
case 'user_order_promotion': case 'user_order_promotion':
return "订单推广佣金{$amount}"; return "订单推广佣金{$amount}";
@ -181,6 +182,12 @@ class CapitalFlowLogic extends BaseLogic
return "用户减少{$amount}"; return "用户减少{$amount}";
case 'user_withdrawal': case 'user_withdrawal':
return "用户提现{$amount}"; return "用户提现{$amount}";
case 'now_money_refund':
return "订单退回到余额{$amount}";
case 'purchase_refund':
return "订单退回到采购款{$amount}";
case 'store_paid_deposit_add':
return "门店增加保证金{$amount}";
default: default:
return "订单支付{$amount}"; return "订单支付{$amount}";
} }

View File

@ -7,7 +7,9 @@ use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct; use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\user\User;
use PDO; use PDO;
use support\Log;
/** /**
* 产品佣金计算 * 产品佣金计算
@ -21,20 +23,26 @@ class CommissionProductLogic extends BaseLogic
*/ */
function calculate_product_flow($find, $order, $village_uid = 0, $brigade_uid = 0, $user_ship = 0, $spread_user_ship = 0) function calculate_product_flow($find, $order, $village_uid = 0, $brigade_uid = 0, $user_ship = 0, $spread_user_ship = 0)
{ {
$product = StoreBranchProduct::where('id', $find['product_id'])->where('store_id', $order['store_id'])->find(); $product = StoreProduct::where('id', $find['product_id'])->find();
if (!$product) {
$product = StoreProduct::where('id', $find['product_id'])->find();
}
if ($product) { if ($product) {
if ($user_ship == 5) { if ($product['product_type'] == 4) {
$top_cate_id = StoreBranchProduct::where('product_id', $find['product_id'])->value('top_cate_id'); $this->c($find, $order, $village_uid, $brigade_uid, $user_ship, $product);
if ($top_cate_id == 15189) { return true;
$this->b($find, $order, $product);
return true;
}
} else { } else {
$this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product); if ($user_ship == 5) {
$top_cate_id = $product['top_cate_id'];
if ($top_cate_id == 15189) {
$this->b($find, $order, $product, $user_ship);
return true;
}
} elseif ($user_ship == 0) {
$this->b($find, $order, $product, $user_ship);
return true;
} else {
$this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product);
}
} }
return true; return true;
} }
} }
@ -44,82 +52,273 @@ class CommissionProductLogic extends BaseLogic
*/ */
public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product) public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product)
{ {
// $rose = bcdiv($product['rose'], 100, 2); $total_price = bcmul($product['price'], $find['cart_num'], 2);
$total_price = bcmul($product['price'], $find['cart_num']); $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2);
// $Distribution = Distribution::where('rate', $rose)->find(); $price = $product['purchase'];
//门店
$data[] = [ $brigade_number = bcmul($purchase_price, 0.02, 2); //队长
'store_id' => $order['store_id'], $village_number = bcmul($brigade_number, 0.1, 2); //村长
'product_id' => $find['product_id'], $platform_number = bcmul($purchase_price, 0.02, 2); //平台
'other_uid' => 0, $attrition_number = bcmul($purchase_price, 0.01, 2); //损耗
'number' => bcmul($total_price, 0.05, 2),
'oid' => $order['id'], $number1 = bcadd($brigade_number, $village_number, 2);
'type' => 1, $number2 = bcadd($number1, $platform_number, 2);
'status' => 1,
]; //零售-供货价
//平台 $number3 = bcsub($total_price, $purchase_price, 2);
$data[] = [
'store_id' => $order['store_id'], $number4 = bcadd($attrition_number, $number2, 2);
'product_id' => $find['product_id'],
'other_uid' => 0, //会员
'number' => bcmul($total_price, 0.02, 2), $uid = 0;
'oid' => $order['id'], if ($order['spread_uid'] > 0) {
'type' => 2, $uid = $order['spread_uid'];
'status' => 1, }
]; if ($order['uid'] > 0) {
//村长 $uid = $order['uid'];
$data[] = [ }
'store_id' => $order['store_id'], $user = User::where('id', $uid)->find();
'product_id' => $find['product_id'], $delete_time=null;
'other_uid' => $village_uid, $nickname='会员';
'number' => bcmul($total_price, 0.01, 2), if ($user) {
'oid' => $order['id'], $moeny = bcsub($user['total_recharge_amount'], $user['purchase_funds'], 2);
'type' => 3, if ($moeny < $user['first_purchase_funds']) {
'status' => 1, $delete_time=1;
]; $nickname='首充没用完,会员不分配';
}
}
if (in_array($user_ship, [2, 3])) {
$vip_number = bcmul($purchase_price, 0.05, 2); //会员利润
$data[] = [
'nickname' => $nickname,
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'price' => $price,
'other_uid' => $uid,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.05,
'number' => $vip_number,
'oid' => $order['id'],
'type' => 0,
'status' => 1,
'delete_time'=>$delete_time
];
$number4 = bcadd($number4, $vip_number, 2);
} else {
$vip_number = bcmul($purchase_price, 0.07, 2); //会员利润
$data[] = [
'nickname' => $nickname,
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => $uid,
'price' => $price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.07,
'number' => $vip_number,
'oid' => $order['id'],
'type' => 0,
'status' => 1,
'delete_time'=>$delete_time
];
$number4 = bcadd($number4, $vip_number, 2);
}
//门店利润
if ($number3 <= 0) {
$store_number = 0;
} else {
$store_number = bcsub($number3, $number4, 2);
}
//队长 //队长
$data[] = [ $data[] = [
'nickname' => '零售队长',
'store_id' => $order['store_id'], 'store_id' => $order['store_id'],
'product_id' => $find['product_id'], 'product_id' => $find['product_id'],
'other_uid' => $brigade_uid, 'other_uid' => 0,
'number' => bcmul($total_price, 0.01, 2), 'price' => $price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.02,
'number' => $brigade_number,
'oid' => $order['id'], 'oid' => $order['id'],
'type' => 4, 'type' => 4,
'status' => 1, 'status' => 1,
'is_activity' => 1,
]; ];
//会员 //村长
if ($user_ship == 1) {
$uid = $order['spread_uid'];
} else {
$uid = 0;
}
// $data[] = [
// 'store_id' => $order['store_id'],
// 'product_id' => $find['product_id'],
// 'other_uid' => $uid,
// 'number' => bcmul($total_price, $Distribution['user'], 2),
// 'oid' => $order['id'],
// 'type' => 0,
// 'status' => 1,
// ];
//个人店铺
if ($order['spread_uid'] > 0) {
$data[] = [
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => $order['spread_uid'],
'number' => bcmul($total_price, 0.07, 2),
'oid' => $order['id'],
'type' => 5,
'status' => 1,
];
}
$data[] = [ $data[] = [
'nickname' => '零售村长',
'store_id' => $order['store_id'], 'store_id' => $order['store_id'],
'product_id' => $find['product_id'], 'product_id' => $find['product_id'],
'other_uid' => 0, 'other_uid' => 0,
'number' => bcmul($total_price, 0.01, 2), 'price' => $price,
'total_price' => $brigade_number,
'cart_num' => 0,
'rate' => 0.01,
'number' => $village_number,
'oid' => $order['id'],
'type' => 3,
'status' => 1,
'is_activity' => 1,
];
//门店
$data[] = [
'nickname' => '零售门店',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $total_price,
'cart_num' => $find['cart_num'],
'rate' => 0,
'number' => $store_number,
'oid' => $order['id'],
'type' => 1,
'status' => 1,
'is_activity' => 1,
];
//平台
$data[] = [
'nickname' => '零售平台',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.02,
'number' => $platform_number,
'oid' => $order['id'],
'type' => 2,
'status' => 1,
'is_activity' => 1,
];
$data[] = [
'nickname' => '零售消耗',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.01,
'number' => $attrition_number,
'oid' => $order['id'],
'type' => 6,
'status' => 1,
];
(new StoreFinanceFlowProduct())->saveAll($data);
}
/**
* 商户价结算
*/
public function b($find, $order, $product, $user_ship)
{
$total_price = bcmul($product['price'], $find['cart_num'], 2);
$purchase_price = bcmul($product['purchase'], $find['cart_num'], 2);
$price = $product['purchase'];
$brigade_number = bcmul($purchase_price, 0.02, 2); //队长
$village_number = bcmul($brigade_number, 0.1, 2); //村长
$platform_number = bcmul($purchase_price, 0.02, 2); //平台
$attrition_number = bcmul($purchase_price, 0.01, 2); //损耗
$number1 = bcadd($brigade_number, $village_number, 2);
$number2 = bcadd($number1, $platform_number, 2);
//零售-供货价
$number3 = bcsub($total_price, $purchase_price, 2);
$number4 = bcadd($attrition_number, $number2, 2);
//门店利润
if ($number3 <= 0) {
$store_number = 0;
} else {
$store_number = bcsub($number3, $number4, 2);
}
//队长
$data[] = [
'nickname' => '商户价队长预留',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.02,
'number' => $brigade_number,
'oid' => $order['id'],
'type' => 4,
'status' => 1,
'is_activity' => 1,
];
//村长
$data[] = [
'nickname' => '商户价村长预留',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $brigade_number,
'cart_num' => 0,
'rate' => 0.01,
'number' => $village_number,
'oid' => $order['id'],
'type' => 3,
'status' => 1,
'is_activity' => 1,
];
//门店
$data[] = [
'nickname' => '商户价门店',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $total_price,
'cart_num' => $find['cart_num'],
'rate' => 0,
'number' => $store_number,
'oid' => $order['id'],
'type' => 1,
'status' => 1,
'is_activity' => 1,
];
//平台
$data[] = [
'nickname' => '商户价平台',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.02,
'number' => $platform_number,
'oid' => $order['id'],
'type' => 2,
'status' => 1,
'is_activity' => 1,
];
$data[] = [
'nickname' => '商户价消耗',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.01,
'number' => $attrition_number,
'oid' => $order['id'], 'oid' => $order['id'],
'type' => 6, 'type' => 6,
'status' => 1, 'status' => 1,
@ -127,32 +326,93 @@ class CommissionProductLogic extends BaseLogic
(new StoreFinanceFlowProduct())->saveAll($data); (new StoreFinanceFlowProduct())->saveAll($data);
} }
/** //活动商品结算
* 商户价结算 public function c($find, $order, $village_uid, $brigade_uid, $user_ship, $product)
*/
public function b($find, $order, $product)
{ {
// $rose = bcdiv($product['rose'], 100, 2); // $rose = bcdiv($product['rose'], 100, 2);
$total_price = bcmul($product['purchase'], $find['cart_num']); $total_price = bcmul($product['price'], $find['cart_num'], 2);
$purchase_price = bcmul($product['purchase'], $find['cart_num'], 2);
$price = $product['price'];
$brigade_number = bcmul($total_price, 0.02, 2); //队长
$village_number = bcmul($brigade_number, 0.1, 2); //村长
$platform_number = bcmul($total_price, 0.02, 2); //平台
$number1 = bcadd($brigade_number, $village_number, 2);
$number2 = bcadd($number1, $platform_number, 2);
//零售-供货价
$number3 = bcsub($total_price, $purchase_price, 2);
//门店利润
if ($number3 <= 0) {
$store_number = 0;
} else {
$store_number = bcsub($number3, $number2, 2);
}
//队长
$data[] = [
'nickname' => '活动队长',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => $brigade_uid,
'price' => $price,
'total_price' => $total_price,
'cart_num' => $find['cart_num'],
'rate' => 0.02,
'number' => $brigade_number,
'oid' => $order['id'],
'type' => 4,
'status' => 1,
'is_activity' => 1,
];
//村长
$data[] = [
'nickname' => '活动村长',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => $village_uid,
'price' => $price,
'total_price' => $brigade_number,
'cart_num' => 0,
'rate' => 0.01,
'number' => $village_number,
'oid' => $order['id'],
'type' => 3,
'status' => 1,
'is_activity' => 1,
];
//门店 //门店
$data[] = [ $data[] = [
'nickname' => '活动门店',
'store_id' => $order['store_id'], 'store_id' => $order['store_id'],
'product_id' => $find['product_id'], 'product_id' => $find['product_id'],
'other_uid' => 0, 'other_uid' => 0,
'number' => bcmul($total_price, 0.05, 2), 'price' => $price,
'total_price' => $store_number,
'cart_num' => $find['cart_num'],
'rate' => 0,
'number' => $store_number,
'oid' => $order['id'], 'oid' => $order['id'],
'type' => 1, 'type' => 1,
'status' => 1, 'status' => 1,
'is_activity' => 1,
]; ];
//平台 //平台
$data[] = [ $data[] = [
'nickname' => '活动平台',
'store_id' => $order['store_id'], 'store_id' => $order['store_id'],
'product_id' => $find['product_id'], 'product_id' => $find['product_id'],
'other_uid' => 0, 'other_uid' => 0,
'number' => bcmul($total_price, 0.02, 2), 'price' => $price,
'total_price' => $platform_number,
'cart_num' => $find['cart_num'],
'rate' => 0.02,
'number' => $platform_number,
'oid' => $order['id'], 'oid' => $order['id'],
'type' => 2, 'type' => 2,
'status' => 1, 'status' => 1,
'is_activity' => 1,
]; ];
(new StoreFinanceFlowProduct())->saveAll($data); (new StoreFinanceFlowProduct())->saveAll($data);
} }

View File

@ -106,7 +106,7 @@ class CommissionnLogic extends BaseLogic
$financeLogic = new StoreFinanceFlowLogic(); $financeLogic = new StoreFinanceFlowLogic();
$financeLogic->order = $order; $financeLogic->order = $order;
$financeLogic->user['uid'] = $order['uid']; $financeLogic->user['uid'] = $order['uid'];
$pay_price = $order['pay_price']; $pay_price=bcsub($order['pay_price'],$order['refund_price'],2);
$number = StoreFinanceFlowProduct::where('oid', $order['id'])->sum('number'); $number = StoreFinanceFlowProduct::where('oid', $order['id'])->sum('number');
$fees = bcsub($pay_price, $number, 2); $fees = bcsub($pay_price, $number, 2);
if ($fees > 0) { if ($fees > 0) {
@ -124,7 +124,7 @@ class CommissionnLogic extends BaseLogic
$financeLogic->user['uid'] = $order['uid']; $financeLogic->user['uid'] = $order['uid'];
$financeLogic->other_arr['vip_uid'] = $uid; $financeLogic->other_arr['vip_uid'] = $uid;
$financeLogic->order = $order; $financeLogic->order = $order;
$financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 $financeLogic->in($transaction_id, bcsub($order['pay_price'],$order['refund_price'],2), OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付
//缴纳齐全了就加商户没有就加到平台 //缴纳齐全了就加商户没有就加到平台
$money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find(); $money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find();

View File

@ -2,6 +2,7 @@
namespace app\common\logic; namespace app\common\logic;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\logic\user_ship\UserShipLogic; use app\admin\logic\user_ship\UserShipLogic;
use app\api\logic\order\OrderLogic; use app\api\logic\order\OrderLogic;
use app\common\enum\OrderEnum; use app\common\enum\OrderEnum;
@ -30,6 +31,7 @@ use app\common\model\user_sign\UserSign;
use app\common\model\vip_flow\VipFlow; use app\common\model\vip_flow\VipFlow;
use app\common\service\Curl; use app\common\service\Curl;
use app\common\service\PushService; use app\common\service\PushService;
use support\exception\BusinessException;
use support\Log; use support\Log;
use think\facade\Db; use think\facade\Db;
use Webman\RedisQueue\Redis; use Webman\RedisQueue\Redis;
@ -52,7 +54,7 @@ class PayNotifyLogic extends BaseLogic
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile()); Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile());
throw new \Exception($e->getMessage()); throw new BusinessException($e->getMessage());
} }
} }
@ -70,13 +72,14 @@ class PayNotifyLogic extends BaseLogic
$order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
$user = User::where('id', $order['uid'])->find(); $user = User::where('id', $order['uid'])->find();
if ($user['now_money'] < $order['pay_price']) { if ($user['now_money'] < $order['pay_price']) {
throw new \Exception('余额不足'); throw new BusinessException('余额不足');
} }
// $order->money = $order['pay_price']; // $order->money = $order['pay_price'];
$order->paid = 1; $order->paid = 1;
$order->status = 1;
$order->pay_time = time(); $order->pay_time = time();
if (!$order->save()) { if (!$order->save()) {
throw new \Exception('订单保存出错'); throw new BusinessException('订单保存出错');
} }
if ($order['is_storage'] == 1) { if ($order['is_storage'] == 1) {
$order->status = 2; $order->status = 2;
@ -95,7 +98,7 @@ class PayNotifyLogic extends BaseLogic
// self::addUserSing($order); // self::addUserSing($order);
$capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao = new CapitalFlowLogic($user);
$capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 3, $order['store_id']); $capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 3, $order['store_id']);
self::dealProductLog($order); // self::dealProductLog($order);
self::afterPay($order); self::afterPay($order);
if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) {
@ -105,14 +108,14 @@ class PayNotifyLogic extends BaseLogic
]; ];
self::dealGoodsLeft($checkArr, $order['uid'], $order['id']); self::dealGoodsLeft($checkArr, $order['uid'], $order['id']);
} }
if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) { // if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) {
$params = [ // $params = [
'verify_code' => $order['verify_code'], // 'verify_code' => $order['verify_code'],
'store_id' => $order['store_id'], // 'store_id' => $order['store_id'],
'staff_id' => $order['staff_id'] // 'staff_id' => $order['staff_id']
]; // ];
OrderLogic::writeOff($params); // OrderLogic::writeOff($params);
} // }
if (in_array($order['shipping_type'], [1, 2])) { if (in_array($order['shipping_type'], [1, 2])) {
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
} }
@ -161,7 +164,7 @@ class PayNotifyLogic extends BaseLogic
]; ];
UserSign::create($sing); UserSign::create($sing);
self::dealProductLog($order); // self::dealProductLog($order);
} }
@ -183,6 +186,7 @@ class PayNotifyLogic extends BaseLogic
} }
$order->money = $order['pay_price']; $order->money = $order['pay_price'];
$order->paid = 1; $order->paid = 1;
$order->status = 1;
$order->pay_time = time(); $order->pay_time = time();
if (!$order->save()) { if (!$order->save()) {
throw new \Exception('订单保存出错'); throw new \Exception('订单保存出错');
@ -192,8 +196,7 @@ class PayNotifyLogic extends BaseLogic
UserProductStorageLogic::add($order); UserProductStorageLogic::add($order);
} }
// 减去采购款 // 减去采购款
$user->purchase_funds = bcsub($user['purchase_funds'], $order['pay_price'], 2); User::update(['purchase_funds' => bcsub($user['purchase_funds'], $order['pay_price'], 2)], ['id' => $user['id']]);
$user->save();
$capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao = new CapitalFlowLogic($user);
$capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $order['id'], $order['pay_price'], '', 18, $order['store_id']); $capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $order['id'], $order['pay_price'], '', 18, $order['store_id']);
@ -202,15 +205,15 @@ class PayNotifyLogic extends BaseLogic
// } // }
// self::addUserSing($order); // self::addUserSing($order);
self::afterPay($order); self::afterPay($order);
if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) { // if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) {
$params = [ // $params = [
'verify_code' => $order['verify_code'], // 'verify_code' => $order['verify_code'],
'store_id' => $order['store_id'], // 'store_id' => $order['store_id'],
'staff_id' => $order['staff_id'] // 'staff_id' => $order['staff_id']
]; // ];
OrderLogic::writeOff($params); // OrderLogic::writeOff($params);
} // }
self::dealProductLog($order); // self::dealProductLog($order);
if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) {
$checkArr = [ $checkArr = [
'cart_id' => $order['cart_id'], 'cart_id' => $order['cart_id'],
@ -252,7 +255,7 @@ class PayNotifyLogic extends BaseLogic
} }
$user = User::where('id', $order['uid'])->find(); $user = User::where('id', $order['uid'])->find();
if ($order->pay_type == OrderEnum::CASHIER_ORDER_PAY || $order->pay_type == OrderEnum::CASHIER_ORDER_ALI_PAY) { //收银台支付 if ($order->pay_type == OrderEnum::CASHIER_ORDER_PAY || $order->pay_type == OrderEnum::CASHIER_ORDER_ALI_PAY) { //收银台支付
$order->status = 2; // $order->status = 2;
} else { } else {
$capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao = new CapitalFlowLogic($user);
//微信支付和用户余额无关 //微信支付和用户余额无关
@ -268,7 +271,7 @@ class PayNotifyLogic extends BaseLogic
} }
self::afterPay($order, $extra['transaction_id']); self::afterPay($order, $extra['transaction_id']);
// self::addUserSing($order); // self::addUserSing($order);
self::dealProductLog($order); // self::dealProductLog($order);
if (!empty($extra['payer']['openid']) && $order->pay_type == 7) { if (!empty($extra['payer']['openid']) && $order->pay_type == 7) {
Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 4]); Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 4]);
@ -323,34 +326,10 @@ class PayNotifyLogic extends BaseLogic
//订单购物详情 //订单购物详情
StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]); StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]);
self::balance_purchase_refund($order);
//处理财务流水退还 //处理财务流水退还
(new StoreFinanceFlowLogic())->store_finance_back($orderSn, $order['store_id']); (new StoreFinanceFlowLogic())->store_finance_back($orderSn, $order['store_id']);
if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付
$user = User::where('id', $order['uid'])->findOrEmpty();
$capitalFlowDao = new CapitalFlowLogic($user);
$user->now_money = bcadd($user['now_money'], $order['pay_price'], 2);
$user->save();
//增加数量
self::addStock($order['id']);
//退款
$capitalFlowDao->userIncome('system_balance_add', 'system_back', $order['id'], $order['pay_price']);
}
if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付
$user = User::where('id', $order['uid'])->findOrEmpty();
$capitalFlowDao = new CapitalFlowLogic($user);
$user->purchase_funds = bcadd($user['purchase_funds'], $order['pay_price'], 2);
$user->save();
//增加数量
self::addStock($order['id']);
//退款
$capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $order['pay_price']);
}
UserSignLogic::RefundOrder($order);
return true;
}
//积分 //积分
UserSignLogic::RefundOrder($order); UserSignLogic::RefundOrder($order);
//微信日志 user_order_refund //微信日志 user_order_refund
@ -361,6 +340,48 @@ class PayNotifyLogic extends BaseLogic
return true; return true;
} }
/**
* 余额采购款退款
*/
public static function balance_purchase_refund($order, $type = 1, $money = 0)
{
if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付
$user = User::where('id', $order['uid'])->findOrEmpty();
$capitalFlowDao = new CapitalFlowLogic($user);
if ($type == 1) {
$capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $order['pay_price'], '', 0);
$user->now_money = bcadd($user['now_money'], $order['pay_price'], 2);
StoreOrder::where('id', $order['id'])->update(['refund_status' => 2]);
} else {
$capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $money, '', 0);
$user->now_money = bcadd($user['now_money'], $money, 2);
}
$user->save();
//增加数量
self::addStock($order['id']);
}
if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付
$user = User::where('id', $order['uid'])->findOrEmpty();
$capitalFlowDao = new CapitalFlowLogic($user);
if ($type == 1) {
$capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $order['pay_price'], '', 1);
$user->purchase_funds = bcadd($user['purchase_funds'], $order['pay_price'], 2);
StoreOrder::where('id', $order['id'])->update(['refund_status' => 2]);
} else {
$capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $money, '', 1);
$user->purchase_funds = bcadd($user['purchase_funds'], $money, 2);
}
$user->save();
//增加数量
self::addStock($order['id']);
}
UserSignLogic::RefundOrder($order);
return true;
}
}
/** /**
* 现金退款相关 * 现金退款相关
* @param $orderSn * @param $orderSn
@ -487,7 +508,8 @@ class PayNotifyLogic extends BaseLogic
} }
$order->paid = 1; $order->paid = 1;
$order->pay_time = time(); $order->pay_time = time();
$order->status = 2; $order->status = 1;
// $order->status = 2;
if ($order['reservation'] == 1) { if ($order['reservation'] == 1) {
$order->status = 1; $order->status = 1;
} }
@ -500,16 +522,16 @@ class PayNotifyLogic extends BaseLogic
} }
$cashFlowLogic = new CashFlowLogic(); $cashFlowLogic = new CashFlowLogic();
$cashFlowLogic->insert($order['store_id'], $order['pay_price']); $cashFlowLogic->insert($order['store_id'], $order['pay_price']);
self::dealProductLog($order); // self::dealProductLog($order);
if ($order && $order['store_id'] && $order['reservation'] != 1) { // if ($order && $order['store_id'] && $order['reservation'] != 1) {
$params = [ // $params = [
'verify_code' => $order['verify_code'], // 'verify_code' => $order['verify_code'],
'store_id' => $order['store_id'], // 'store_id' => $order['store_id'],
'staff_id' => $order['staff_id'] // 'staff_id' => $order['staff_id']
]; // ];
OrderLogic::writeOff($params); // OrderLogic::writeOff($params);
} // }
// Redis::send('push-platform-print', ['id' => $order['id']]); // Redis::send('push-platform-print', ['id' => $order['id']]);
@ -544,7 +566,7 @@ class PayNotifyLogic extends BaseLogic
} }
$order->save(); $order->save();
self::afterPay($order); self::afterPay($order);
self::dealProductLog($order); // self::dealProductLog($order);
// if ($order->pay_type == 9) { // if ($order->pay_type == 9) {
// $extra['create_time'] = $order['create_time']; // $extra['create_time'] = $order['create_time'];
@ -554,14 +576,14 @@ class PayNotifyLogic extends BaseLogic
// else { // else {
// PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
// } // }
if ($order->pay_type == 13) { // if ($order->pay_type == 13) {
$params = [ // $params = [
'verify_code' => $order['verify_code'], // 'verify_code' => $order['verify_code'],
'store_id' => $order['store_id'], // 'store_id' => $order['store_id'],
'staff_id' => $order['staff_id'] // 'staff_id' => $order['staff_id']
]; // ];
OrderLogic::writeOff($params); // OrderLogic::writeOff($params);
} // }
return true; return true;
} }
@ -574,20 +596,39 @@ class PayNotifyLogic extends BaseLogic
{ {
StoreOrderCartInfo::where('oid', $order['id'])->update(['is_pay' => 1]); StoreOrderCartInfo::where('oid', $order['id'])->update(['is_pay' => 1]);
$arr = StoreOrderCartInfo::where('oid', $order['id'])->field('id,oid,product_id,store_id,cart_num')->select(); $arr = StoreOrderCartInfo::where('oid', $order['id'])->field('id,oid,product_id,store_id,cart_num')->select();
foreach ($arr as $k => $v) { try {
$branchProduct=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id',$v['store_id'])->find(); foreach ($arr as $k => $v) {
if($branchProduct){ $branchProduct = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $v['store_id'])->find();
$stock=bcsub($branchProduct['stock'],$v['cart_num'],2); $storeProduct = StoreProduct::where('id', $v['product_id'])->find();
StoreProduct::where('id',$branchProduct['id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$branchProduct['purchase'],2),
'sales'=>bcmul($branchProduct['sales'],$v['cart_num'],2)]); if ($branchProduct) {
} $stock = bcsub($branchProduct['stock'], $v['cart_num'], 2);
$storeProduct=StoreProduct::where('id', $v['product_id'])->find(); StoreBranchProduct::update([
if($storeProduct){ 'stock' => $stock,
$stock=bcsub($storeProduct['stock'],$v['cart_num'],2); 'total_price' => bcmul($stock, $branchProduct['purchase'], 2),
StoreProduct::where('id', $v['product_id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$storeProduct['purchase'],2), 'sales' => bcadd($branchProduct['sales'], $v['cart_num'], 2)
'sales'=>bcmul($storeProduct['sales'],$v['cart_num'],2)]); ], ['id' => $branchProduct['id']]);
} else {
StoreProductLogic::ordinary(['id' => $v['product_id']], $v['store_id'], 0, $storeProduct);
StoreBranchProduct::update([
'stock' => -$v['cart_num'],
'sales' => $v['cart_num']
], ['product_id' => $v['product_id'],'store_id'=>$v['store_id']]);
}
if ($storeProduct) {
$stock = bcsub($storeProduct['stock'], $v['cart_num'], 2);
StoreProduct::update([
'stock' => $stock,
'total_price' => bcmul($stock, $storeProduct['purchase'], 2),
'sales' => bcadd($storeProduct['sales'], $v['cart_num'], 2)
], ['id' => $v['product_id']]);
}
} }
} catch (\Throwable $e) {
Log::error('订单库存更新失败:' . $e->getMessage());
// 异常处理代码,例如记录日志或发送通知等。
} }
$financeLogic = new StoreFinanceFlowLogic(); $financeLogic = new StoreFinanceFlowLogic();
$off_activity = Config::where('name', 'off_activity')->value('value'); $off_activity = Config::where('name', 'off_activity')->value('value');
$village_uid = 0; $village_uid = 0;
@ -623,108 +664,35 @@ class PayNotifyLogic extends BaseLogic
return false; return false;
} }
//如果是会员需要返回会员金额 if ($order['uid'] > 0) {
// if ($user_ship>0 && $order['pay_type'] != PayEnum::CASH_PAY && $off_activity !=1) { $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
// $order['dealVipAmount']= self::dealVipAmount($order, $order['pay_type']); if ($address) {
// } $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
if ($order['spread_uid'] > 0 || $user_ship > 0) { if ($arr1) {
if ($order['spread_uid'] > 0 && $user_ship == 0) { $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
$user_ship = User::where('id', $order['spread_uid'])->value('user_ship');
if ($user_ship == 2) {
$village_uid = $order['spread_uid'];
$address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find();
if ($address) {
$arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
if ($arr2) {
$brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
}
}
} elseif ($user_ship == 3) {
$brigade_uid = $order['spread_uid'];
$address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find();
if ($address) {
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
if ($arr1) {
$village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
}
}
} else {
$address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find();
if ($address) {
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
if ($arr1) {
$village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
}
$arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
if ($arr2) {
$brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
}
}
} }
} else { $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
//查询用户对应的村长和队长 if ($arr2) {
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
if ($address) {
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
if ($arr1) {
$village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
}
$arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
if ($arr2) {
$brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
}
} }
} }
if (isset($user) && $order['store_id'] == getenv('ACTIVITY_STORE_ID') && !in_array($user['user_ship'], [4, 6, 7])) {
try {
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();
$comm = new CommissionProductLogic();
foreach ($info as $k => $v) {
$comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship);
}
CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id);
return true;
} catch (\Exception $e) {
Log::error('活动分润报错' . $e->getMessage());
return false;
}
}
switch ($user_ship) {
case 1: // 厨师
//case 4: // 商户
//case 5: // 种养殖
// case 6: // 酒店
// case 7: // 食堂
case 8: // 一条龙
CommissionLogic::setCook($order, $village_uid, $brigade_uid, $transaction_id);
break;
case 2: // 村长
CommissionLogic::setVillage($order, $village_uid, $brigade_uid, $transaction_id);
break;
case 3: // 队长
CommissionLogic::setBrigade($order, $village_uid, $brigade_uid, $transaction_id);
break;
default:
CommissionLogic::setStore($order, $transaction_id);
break;
}
} else {
if (isset($user) && $order['store_id'] == getenv('ACTIVITY_STORE_ID') && !in_array($user['user_ship'], [4, 6, 7])) {
try {
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();
$comm = new CommissionProductLogic();
foreach ($info as $k => $v) {
$comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship);
}
CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id);
return true;
} catch (\Exception $e) {
Log::error('活动分润报错' . $e->getMessage());
return false;
}
}
CommissionLogic::setStore($order, $transaction_id);
} }
if ($order['spread_uid'] > 0) {
$user_ship = User::where('id', $order['spread_uid'])->value('user_ship');
}
try {
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();
$comm = new CommissionProductLogic();
foreach ($info as $k => $v) {
$comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship);
}
CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id);
} catch (\Throwable $e) {
Log::error('分润报错' . $e->getMessage());
return false;
}
return true;
} }
/** /**

View File

@ -8,7 +8,9 @@ use app\common\enum\PayEnum;
use app\common\model\user\UserAuth; use app\common\model\user\UserAuth;
use app\common\service\pay\PayService; use app\common\service\pay\PayService;
use Exception; use Exception;
use support\exception\BusinessException;
use support\Log; use support\Log;
use Throwable;
use function DI\string; use function DI\string;
@ -40,34 +42,33 @@ class PaymentLogic extends BaseLogic
return ['pay_way' => PayEnum::BALANCE_PAY]; return ['pay_way' => PayEnum::BALANCE_PAY];
} }
try { try {
if(isset($order['price'])){ if (isset($order['price'])) {
$order['pay_price'] = $order['price']; $order['pay_price'] = $order['price'];
} }
switch ($payWay) { switch ($payWay) {
case PayEnum::WECHAT_PAY_MINI: case PayEnum::WECHAT_PAY_MINI:
$auth = UserAuth::where(['user_id' => $order['uid'], 'terminal' => $terminal])->findOrEmpty(); $auth = UserAuth::where(['user_id' => $order['uid'], 'terminal' => $terminal])->findOrEmpty();
$order = [ $order = [
'out_trade_no' => $paySn, 'out_trade_no' => $paySn,
'description' => '商品', 'description' => '商品',
'amount' => [ 'amount' => [
'total' => intval($order['pay_price'] * 100), 'total' => intval($order['pay_price'] * 100),
'currency' => 'CNY', 'currency' => 'CNY',
], ],
"payer" => [ "payer" => [
"openid" => $auth['openid'] "openid" => $auth['openid']
], ],
'attach' => $from 'attach' => $from
]; ];
$wechat = new PayService(1); $wechat = new PayService(1);
$result = $wechat->wechat->mini($order)->toArray(); $result = $wechat->wechat->mini($order)->toArray();
break; break;
default: default:
self::$error = '订单异常'; throw new BusinessException('支付方式异常');
$result = false; }
} } catch (Throwable $e) {
} catch (Exception $e) { Log::info($e->extra['message'] ?? $e->getMessage());
\support\Log::info($e->extra['message']?? $e->getMessage()); throw new BusinessException($e->extra['message'] ?? $e->getMessage());
throw new \Exception($e->extra['message']?? $e->getMessage());
} }
return $result; return $result;
} }
@ -75,13 +76,12 @@ class PaymentLogic extends BaseLogic
/** /**
* 微信条码支付 * 微信条码支付
*/ */
public static function codepay($auth_code, $order,$description='条码商品') public static function codepay($auth_code, $order, $description = '条码商品')
{ {
$pattern = '/^(10|11|12|13|14|15)\d{16}$/'; $pattern = '/^(10|11|12|13|14|15)\d{16}$/';
if (!preg_match($pattern, (string)$auth_code)) { if (!preg_match($pattern, (string)$auth_code)) {
self::$error = '请使用正确的微信收付款条码'; throw new BusinessException('请使用正确的微信收付款条码');
return false;
} }
$data = [ $data = [
'description' => $description, 'description' => $description,
@ -94,26 +94,25 @@ class PaymentLogic extends BaseLogic
], ],
'scene_info' => [ 'scene_info' => [
"store_info" => [ "store_info" => [
'id' => (string)$order['store_id']??1 'id' => (string)$order['store_id'] ?? 1
] ]
], ],
'attach'=>'wechat_common' 'attach' => 'wechat_common'
]; ];
if(isset($order['attach']) && $order['attach']!=''){ if (isset($order['attach']) && $order['attach'] != '') {
$data['attach'] = $order['attach']; $data['attach'] = $order['attach'];
} }
$wechat = new PayService(1); $wechat = new PayService(1);
try { try {
$result = $wechat->wechat->pos($data)->toArray(); $result = $wechat->wechat->pos($data)->toArray();
} catch (Exception $e) { } catch (Throwable $e) {
Log::error('条码支付报错',['message' => $e->extra['message']?? $e->getMessage(),'code'=>$e->getCode()]); Log::error('条码支付报错', ['message' => $e->extra['message'] ?? $e->getMessage(), 'code' => $e->getCode()]);
if (getenv('APP_DEBUG') == true) { if (getenv('APP_DEBUG') == true) {
self::$error = $e->extra['message'] ?? $e->getMessage(); throw new BusinessException($e->extra['message'] ?? $e->getMessage());
} else { } else {
self::$error = $e->getMessage(); throw new BusinessException($e->getMessage());
} }
return false;
} }
return $result; return $result;
} }
@ -126,26 +125,24 @@ class PaymentLogic extends BaseLogic
$pattern = '/^(25|26|27|28|29|30)[0-9A-Za-z]{14,23}$/'; $pattern = '/^(25|26|27|28|29|30)[0-9A-Za-z]{14,23}$/';
if (!preg_match($pattern, (string)$auth_code)) { if (!preg_match($pattern, (string)$auth_code)) {
self::$error = '请使用正确的支付宝收付款条码'; throw new BusinessException('请使用正确的支付宝收付款条码');
return false;
} }
$order = [ $order = [
'subject' => '条码商品', 'subject' => '条码商品',
'out_trade_no' => (string)$order['order_id'], 'out_trade_no' => (string)$order['order_id'],
'auth_code' => (string)$auth_code, 'auth_code' => (string)$auth_code,
'total_amount' => $order['pay_price'], 'total_amount' => $order['pay_price'],
'extend_params'=>['attach'=>'alipay_cashier'] 'extend_params' => ['attach' => 'alipay_cashier']
]; ];
$wechat = new PayService(); $wechat = new PayService();
try { try {
$result = $wechat->alipay->pos($order)->toArray(); $result = $wechat->alipay->pos($order)->toArray();
} catch (Exception $e) { } catch (Throwable $e) {
if (getenv('APP_DEBUG') == true) { if (getenv('APP_DEBUG') == true) {
self::$error = $e->extra['message'] ?? $e->getMessage(); throw new BusinessException($e->extra['message'] ?? $e->getMessage());
} else { } else {
self::$error = $e->getMessage(); throw new BusinessException($e->getMessage());
} }
return false;
} }
return $result; return $result;
} }

View File

@ -151,18 +151,18 @@ class StoreFinanceFlowLogic extends BaseLogic
$store = SystemStore::where('id', $store_id)->find(); $store = SystemStore::where('id', $store_id)->find();
$capitalFlowDao = new CapitalFlowLogic($store, 'store'); $capitalFlowDao = new CapitalFlowLogic($store, 'store');
if ($money > 0) { if ($money > 0) {
$capitalFlowDao->storeIncome('store_money_add', 'order', $order_id, $money); $capitalFlowDao->storeIncome('store_money_add', 'order', $order_id, $money,'','store_money');
SystemStore::where('id', $store_id)->inc('store_money', $money)->update(); SystemStore::where('id', $store_id)->inc('store_money', $money)->update();
} }
if ($deposit > 0) { if ($deposit > 0) {
$capitalFlowDao->storeIncome('store_paid_deposit_add', 'order', $order_id, $deposit); $capitalFlowDao->storeIncome('store_paid_deposit_add', 'order', $order_id, $deposit,'','paid_deposit');
SystemStore::where('id', $store_id)->inc('paid_deposit', $deposit)->update(); SystemStore::where('id', $store_id)->inc('paid_deposit', $deposit)->update();
} }
$find = StoreFinanceFlow::where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 16, 'status' => 0])->find(); $find = StoreFinanceFlow::where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 16, 'status' => 0])->find();
StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 16])->update(['status' => 1]); StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 16])->update(['status' => 1]);
if ($find) { if ($find) {
if ($find['number'] > 0) { if ($find['number'] > 0) {
$capitalFlowDao->storeIncome('store_attrition_add', 'order', $order_id, $find['number']); $capitalFlowDao->storeIncome('store_attrition_add', 'order', $order_id, $find['number'],'','attrition');
SystemStore::where('id', $store_id)->inc('attrition', $find['number'])->update(); SystemStore::where('id', $store_id)->inc('attrition', $find['number'])->update();
} }
} }
@ -183,39 +183,40 @@ class StoreFinanceFlowLogic extends BaseLogic
->select(); ->select();
foreach ($list as $k => $value) { foreach ($list as $k => $value) {
//用户 //用户
switch ($value['type']) { if($value['type']==0){
case 0: if ($value['financial_type'] == 12 && $value['other_uid'] > 0) {
if ($value['financial_type'] == 12 && $value['other_uid'] > 0) { $user = User::where('id', $value['other_uid'])->findOrEmpty();
$user = User::where('id', $value['other_uid'])->findOrEmpty(); $capitalFlowDao = new CapitalFlowLogic($user);
$capitalFlowDao = new CapitalFlowLogic($user); $user->now_money = bcsub($user['now_money'], $value['number'], 2);
$user->now_money = bcsub($user['now_money'], $value['number'], 2); $user->save();
$user->save(); $capitalFlowDao->userExpense('user_order_promotion_refund', 'system_back', $value['order_id'], $value['number'], '', $value['pay_type']);
// Log::error('aa'.$a); }
// Log::error('aa'.$user['now_money']); }elseif($value['type']==1){
// Log::error('aa'.$value['number']); $store = SystemStore::where('id', $store_id)->find();
$capitalFlowDao->userExpense('user_order_promotion_refund', 'system_back', $value['order_id'], $value['number'], '', $value['pay_type']); $capitalFlowDao = new CapitalFlowLogic($store, 'store');
} if ($value['number'] > 0 && $value['financial_type'] == 2) {
break; $find=SystemStore::where('id', $value['store_id'])->find();
//商户 $find->store_money=bcsub($find['store_money'], $value['number'],2);
case 1: $find->save();
$store = SystemStore::where('id', $store_id)->find(); $capitalFlowDao->storeExpense('store_money_refund', 'order', $value['order_id'],$value['number'],'','store_money');
$capitalFlowDao = new CapitalFlowLogic($store, 'store');
if ($value['number'] > 0 && $value['financial_type'] == 2) {
SystemStore::where('id', $value['store_id'])->dec('store_money', $value['number'])->update();
$capitalFlowDao->storeExpense('store_paid_deposit_dec', 'order', $value['order_id'],$value['number']);
} }
if ($value['number'] > 0 && $value['financial_type'] == 16) { if ($value['number'] > 0 && $value['financial_type'] == 16) {
SystemStore::where('id', $value['store_id'])->dec('attrition', $value['number'])->update(); $find=SystemStore::where('id', $value['store_id'])->find();
$capitalFlowDao->storeExpense('store_attrition_dec', 'order', $value['order_id'], $value['number']); $find->attrition=bcsub($find['attrition'], $value['number'],2);
$find->save();
$capitalFlowDao->storeExpense('store_attrition_refund', 'order', $value['order_id'], $value['number'],'','attrition');
} }
break;
} }
} }
$find = StoreFinanceFlow::where('order_sn', $orderSn)->where('financial_type', 11)->where('status', 1)->find(); $find = StoreFinanceFlow::where('order_sn', $orderSn)->where('financial_type', 11)->where('status', 1)->find();
if ($find && $find['number'] > 0) { if ($find && $find['number'] > 0) {
SystemStore::where('id', $find['store_id'])->dec('paid_deposit', $find['number'])->update(); $find=SystemStore::where('id', $value['store_id'])->find();
$capitalFlowDao = new CapitalFlowLogic($find, 'store');
$find->paid_deposit=bcsub($find['paid_deposit'], $value['number'],2);
$find->save();
$capitalFlowDao->storeExpense('store_paid_deposit_refund', 'order', $value['order_id'],$value['number'],'','paid_deposit');
} }
// $data = StoreFinanceFlow::where('order_sn', $orderSn)->select(); // $data = StoreFinanceFlow::where('order_sn', $orderSn)->select();
// foreach ($data as $k => &$value) { // foreach ($data as $k => &$value) {

View File

@ -67,7 +67,7 @@ class UserSignLogic extends BaseLogic
$write = self::write($order, $total_vip, 0, 1, 9); $write = self::write($order, $total_vip, 0, 1, 9);
self::write_log($write, $total_vip, 0, 7); self::write_log($write, $total_vip, 0, 7);
self::write_log($write, $total_vip, 0, 9, 0); self::write_log($write, $total_vip, 0, 9, 0);
User::where('id', $order->uid)->inc('integral', $total_vip)->update(); User::where('id', $order->uid)->update(['integral'=>$total_vip,'first_purchase_funds'=>$order['price']]);
} }
return true; return true;
} }

View File

@ -21,6 +21,7 @@ use Exception;
use support\Cache; use support\Cache;
use think\facade\Db; use think\facade\Db;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use support\exception\BusinessException;
class StoreOrderLogic extends BaseLogic class StoreOrderLogic extends BaseLogic
{ {
@ -46,8 +47,7 @@ class StoreOrderLogic extends BaseLogic
$where = ['is_pay' => 0]; $where = ['is_pay' => 0];
$cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray(); $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray();
if (empty($cart_select)) { if (empty($cart_select)) {
self::setError('购物车为空'); throw new BusinessException('购物车为空');
return false;
} }
try { try {
self::$total_price = 0; self::$total_price = 0;
@ -164,8 +164,7 @@ class StoreOrderLogic extends BaseLogic
} }
} catch (\Exception $e) { } catch (\Exception $e) {
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
return ['order' => $order, 'cart_list' => $cart_select]; return ['order' => $order, 'cart_list' => $cart_select];
} }
@ -222,8 +221,8 @@ class StoreOrderLogic extends BaseLogic
return $order; return $order;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
@ -238,7 +237,7 @@ class StoreOrderLogic extends BaseLogic
$query->field(['id', 'oid', 'product_id', 'cart_info']); $query->field(['id', 'oid', 'product_id', 'cart_info']);
}])->where($params)->find(); }])->where($params)->find();
if (empty($order)) { if (empty($order)) {
throw new \Exception('订单不存在'); throw new BusinessException('订单不存在');
} }
$order['pay_time'] = $order['pay_time'] > 0 ? date('Y-m-d H:i:s', $order['pay_time']) : ''; $order['pay_time'] = $order['pay_time'] > 0 ? date('Y-m-d H:i:s', $order['pay_time']) : '';
$order['status_name'] = OrderEnum::getOrderType($order['status']) ?? ''; $order['status_name'] = OrderEnum::getOrderType($order['status']) ?? '';
@ -251,12 +250,31 @@ class StoreOrderLogic extends BaseLogic
if ($order['pay_type'] == 19){ if ($order['pay_type'] == 19){
$order['deduction_price'] = "0.00"; $order['deduction_price'] = "0.00";
} }
$product=StoreOrderCartInfo::where(['oid'=>$order['id']])
$detail =StoreOrderCartInfo::where('oid',$order['id'])->find()->toArray(); ->field('oid,uid,product_id,store_id,cart_num,price,total_price,create_time')
->select()->each(function ($item) {
$find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find();
if($find){
$item['image']=$find['image'];//商品图片
$item['name']=$find['store_name'];//商品名称
$item['store_info']=$find['store_info'];//商品规格
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??"";
$item['pay_price'] =$item['total_price'];
$item['cart_info'] = $item->toArray()??[];
}else{
$item['image']='';//商品图片
$item['unit_name']='';//商品图片
$item['cate_name']='';//商品图片
$item['store_name']='';//商品名称
$item['store_info']='';//商品规格-(数据库叫商品简介)
$item['nickname']='';
$item['system_store']='';
$item['cart_info']=[];
}
return $item; //返回处理后的数据。
});
$order['product']=$product;
$vip =0; $vip =0;
if(isset($detail['cart_info']['vip']) && $detail['cart_info']['vip'] == 1){
$vip = 1;
}
$order['vip'] = $vip; $order['vip'] = $vip;
return $order->toArray(); return $order->toArray();
} }
@ -372,7 +390,7 @@ class StoreOrderLogic extends BaseLogic
return false; return false;
} catch (Exception $e) { } catch (Exception $e) {
\support\Log::info($e->extra['message'] ?? $e->getMessage()); \support\Log::info($e->extra['message'] ?? $e->getMessage());
throw new \Exception($e->extra['message'] ?? $e->getMessage()); throw new BusinessException($e->extra['message'] ?? $e->getMessage());
} }
} }
@ -383,7 +401,7 @@ class StoreOrderLogic extends BaseLogic
$code = generateRandomCode(); $code = generateRandomCode();
$phone = User::where('id',$param['uid'])->value('mobile'); $phone = User::where('id',$param['uid'])->value('mobile');
if(empty($phone)){ if(empty($phone)){
throw new \Exception('用户未设置手机号'); throw new BusinessException('用户未设置手机号');
} }
$template = getenv('SMS_TEMPLATE'); $template = getenv('SMS_TEMPLATE');
$check =(new SmsService())->client($phone,$template,$code); $check =(new SmsService())->client($phone,$template,$code);
@ -413,8 +431,7 @@ class StoreOrderLogic extends BaseLogic
$cart_select = Cart::whereIn('id', $params['cart_id']) $cart_select = Cart::whereIn('id', $params['cart_id'])
->where($where)->field('id,product_id,cart_num,store_id')->select()->toArray(); ->where($where)->field('id,product_id,cart_num,store_id')->select()->toArray();
if (empty($cart_select)) { if (empty($cart_select)) {
self::setError('购物车为空'); throw new BusinessException('购物车为空');
return false;
} }
$newArr = []; $newArr = [];
//检查购物车对比店铺得商品数量差异 //检查购物车对比店铺得商品数量差异

View File

@ -9,6 +9,7 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\user\User; use app\common\model\user\User;
use app\common\model\user_product_storage\UserProductStorage; use app\common\model\user_product_storage\UserProductStorage;
use app\common\model\user_product_storage_log\UserProductStorageLog; use app\common\model\user_product_storage_log\UserProductStorageLog;
use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
/** /**
@ -54,9 +55,7 @@ class UserProductStorageLogic extends BaseLogic
$find=UserProductStorage::where('uid',$uid)->where('product_id',$v['product_id'])->find(); $find=UserProductStorage::where('uid',$uid)->where('product_id',$v['product_id'])->find();
if($find){ if($find){
if($find['nums']<$v['nums']){ if($find['nums']<$v['nums']){
self::setError('库存不足'); throw new BusinessException("库存不足");
Db::commit();
return false;
} }
$nums=bcsub($find['nums'],$v['nums']); $nums=bcsub($find['nums'],$v['nums']);
$find->nums=$nums; $find->nums=$nums;
@ -86,17 +85,14 @@ class UserProductStorageLogic extends BaseLogic
$data_log[$k]['times']=$times; $data_log[$k]['times']=$times;
$data_log[$k]['status']=$status; $data_log[$k]['status']=$status;
}else{ }else{
self::setError('没有查询到该商品'); throw new BusinessException("没有查询到该商品");
Db::commit();
return false;
} }
} }
(new UserProductStorageLog())->saveAll($data_log); (new UserProductStorageLog())->saveAll($data_log);
Db::commit(); Db::commit();
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); throw new BusinessException($e->getMessage());
return false;
} }
} }
} }

View File

@ -7,8 +7,9 @@ use app\common\model\BaseModel;
use app\common\model\store_category\StoreCategory; use app\common\model\store_category\StoreCategory;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
use Illuminate\Support\Facades\Log;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
use Throwable;
/** /**
* 门店商品属性值辅助表模型 * 门店商品属性值辅助表模型
@ -36,10 +37,17 @@ class StoreBranchProduct extends BaseModel
} }
public function store() public function store()
{ {
return $this->hasOne(StoreProduct::class,'id','product_id'); return $this->hasOne(StoreProduct::class,'id','product_id');
} }
public static function onAfterWrite($data){
try{
channelLog($data->getOrigin(),'branch_product','更新前');
channelLog($data->toArray(),'branch_product','更新后');
}catch(Throwable $e){
Log::error('branch_product:'.$e->getMessage());
}
}
} }

View File

@ -7,8 +7,9 @@ use app\common\model\BaseModel;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use app\common\model\system_store\SystemStoreStaff; use app\common\model\system_store\SystemStoreStaff;
use app\common\model\user\User; use app\common\model\user\User;
use Illuminate\Support\Facades\Log;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
use Throwable;
/** /**
* 门店流水模型 * 门店流水模型
@ -36,4 +37,12 @@ class StoreFinanceFlow extends BaseModel
return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->bind(['staff_name']); return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->bind(['staff_name']);
} }
public static function onAfterWrite($data){
try{
channelLog($data->getOrigin(),'store_finance_flow','更新前');
channelLog($data->toArray(),'store_finance_flow','更新后');
}catch(Throwable $e){
Log::error('store_finance_flow:'.$e->getMessage());
}
}
} }

View File

@ -4,8 +4,9 @@ namespace app\common\model\store_finance_flow_product;
use app\common\model\BaseModel; use app\common\model\BaseModel;
use Illuminate\Support\Facades\Log;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
use Throwable;
/** /**
* 财务流水商品明细 * 财务流水商品明细
@ -17,4 +18,13 @@ class StoreFinanceFlowProduct extends BaseModel
use SoftDelete; use SoftDelete;
protected $name = 'store_finance_flow_product'; protected $name = 'store_finance_flow_product';
protected $deleteTime = 'delete_time'; protected $deleteTime = 'delete_time';
public static function onAfterWrite($data){
try{
channelLog($data->getOrigin(),'store_finance_flow_product','更新前');
channelLog($data->toArray(),'store_finance_flow_product','更新后');
}catch(Throwable $e){
Log::error('store_finance_flow_product:'.$e->getMessage());
}
}
} }

View File

@ -9,8 +9,9 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use app\common\model\system_store\SystemStoreStaff; use app\common\model\system_store\SystemStoreStaff;
use app\common\model\user\User; use app\common\model\user\User;
use support\Log;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
use Throwable;
/** /**
* 订单列表模型 * 订单列表模型
@ -99,4 +100,13 @@ class StoreOrder extends BaseModel
})->field("FROM_UNIXTIME(create_time,'$timeType') as days,$str as num") })->field("FROM_UNIXTIME(create_time,'$timeType') as days,$str as num")
->group('days')->select()->toArray(); ->group('days')->select()->toArray();
} }
public static function onAfterWrite($data){
try{
channelLog($data->getOrigin(),'store_order','更新前');
channelLog($data->toArray(),'store_order','更新后');
}catch(Throwable $e){
Log::error('store_order:'.$e->getMessage());
}
}
} }

View File

@ -4,7 +4,9 @@ namespace app\common\model\store_order_cart_info;
use app\common\model\BaseModel; use app\common\model\BaseModel;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use Illuminate\Support\Facades\Log;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
use Throwable;
class StoreOrderCartInfo extends BaseModel class StoreOrderCartInfo extends BaseModel
{ {
@ -18,4 +20,13 @@ class StoreOrderCartInfo extends BaseModel
{ {
return $this->hasOne(StoreBranchProduct::class,'id','product_id')->bind(['store_name','image','unit','price']); return $this->hasOne(StoreBranchProduct::class,'id','product_id')->bind(['store_name','image','unit','price']);
} }
public static function onAfterWrite($data){
try{
channelLog($data->getOrigin(),'store_order_cart_info','更新前');
channelLog($data->toArray(),'store_order_cart_info','更新后');
}catch(Throwable $e){
Log::error('store_order_cart_info:'.$e->getMessage());
}
}
} }

View File

@ -6,8 +6,9 @@ namespace app\common\model\store_product;
use app\common\model\BaseModel; use app\common\model\BaseModel;
use app\common\model\store_category\StoreCategory; use app\common\model\store_category\StoreCategory;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
use support\Log;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
use Throwable;
/** /**
* 商品列表模型 * 商品列表模型
@ -31,8 +32,14 @@ class StoreProduct extends BaseModel
{ {
return $this->hasOne(StoreCategory::class,'id','cate_id')->bind(['class_name'=>'name']); return $this->hasOne(StoreCategory::class,'id','cate_id')->bind(['class_name'=>'name']);
} }
public static function onAfterWrite($data){
try{
channelLog($data->getOrigin(),'product','更新前');
channelLog($data->toArray(),'product','更新后');
}catch(Throwable $e){
Log::error('product:'.$e->getMessage());
}
}
} }

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