更新
This commit is contained in:
parent
68b896f990
commit
6b4e14905c
@ -8,6 +8,7 @@ use app\admin\lists\operation\OpurchaseclassLists;
|
||||
use app\admin\lists\operation\OpurchaseclassofferLists;
|
||||
use app\admin\logic\operation\OpurchaseclassLogic;
|
||||
use app\admin\validate\operation\OpurchaseclassValidate;
|
||||
use app\common\logic\PayNotifyLogic;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\opurchase\OpurchaseGoodsOffer;
|
||||
use app\common\model\opurchase\Opurchaseinfo;
|
||||
@ -43,46 +44,16 @@ class OpurchaseclassController extends BaseAdminController
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
return $this->success('不能添加');
|
||||
$params = (new OpurchaseclassValidate())->post()->goCheck('add');
|
||||
$result = OpurchaseclassLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
$params=$this->request->post();
|
||||
$order=OpurchaseclassLogic::createOpurchaseOrder(request()->userInfo,$params);
|
||||
if($order==false){
|
||||
return $this->fail(OpurchaseclassLogic::getError());
|
||||
}else{
|
||||
PayNotifyLogic::handle('operated', $order['number']);
|
||||
//推送队列
|
||||
Redis::send('push-supplier-products', ['order_id'=>$order['id']]);
|
||||
return $this->success('支付成功');
|
||||
}
|
||||
return $this->fail(OpurchaseclassLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑采购订单
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/04/27 11:26
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
return $this->success('不能编辑');
|
||||
$params = (new OpurchaseclassValidate())->post()->goCheck('edit');
|
||||
$result = OpurchaseclassLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(OpurchaseclassLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除采购订单
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/04/27 11:26
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
return $this->success('不能删除');
|
||||
$params = (new OpurchaseclassValidate())->post()->goCheck('delete');
|
||||
OpurchaseclassLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,6 +17,7 @@ use app\common\lists\ListsSearchInterface;
|
||||
class OpurchaseclassLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
protected $where;
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
@ -27,7 +28,7 @@ class OpurchaseclassLists extends BaseAdminDataLists implements ListsSearchInter
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['merchant', 'order_arr', 'number'],
|
||||
'=' => ['order_arr', 'number','is_mer'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -43,7 +44,15 @@ class OpurchaseclassLists extends BaseAdminDataLists implements ListsSearchInter
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$where=[];
|
||||
$merchant=$this->request->get('merchant');
|
||||
if($merchant){
|
||||
$mer_id= Merchant::where('mer_id','like','%'.$merchant.'%')->column('mer_id');
|
||||
$where['mer_id']=['in',$mer_id];
|
||||
}
|
||||
$this->where=$where;
|
||||
return Opurchaseclass::where($this->searchWhere)
|
||||
->where($where)
|
||||
->field(['id', 'merchant', 'order_arr', 'cart_id', 'number', 'total', 'deduction_price', 'actual', 'money', 'paid'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
@ -63,7 +72,7 @@ class OpurchaseclassLists extends BaseAdminDataLists implements ListsSearchInter
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Opurchaseclass::where($this->searchWhere)->count();
|
||||
return Opurchaseclass::where($this->searchWhere)->where($this->where)->count();
|
||||
}
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ use app\common\model\goods\Goods;
|
||||
use app\common\model\merchant\Merchant;
|
||||
use app\common\model\opurchase\OpurchaseGoodsOffer;
|
||||
use app\common\model\opurchase\Opurchaseinfo;
|
||||
use app\common\model\order\Cart;
|
||||
use app\common\model\retail\Cashierclass;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use support\Log;
|
||||
@ -23,22 +24,85 @@ use think\facade\Db;
|
||||
class OpurchaseclassLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加采购订单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/04/27 11:26
|
||||
/**
|
||||
* @notes 获取购货订单购物车商品信息
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
static public function cartIdByPurchaseOrderInfo($params)
|
||||
{
|
||||
|
||||
$where1 = ['paid' => 1,'is_opurchase'=>0,'is_mer'=>1];
|
||||
$arrs = Opurchaseclass::whereDay('create_time')->where($where1)->column('cart_id,id');
|
||||
|
||||
$cart_arr = [];
|
||||
$order_id = [];
|
||||
foreach ($arrs as $k => $v) {
|
||||
if (empty($v['cart_id'])) {
|
||||
self::setError('没有购物车信息');
|
||||
return false;
|
||||
}
|
||||
$arr = explode(',',$v['cart_id']);
|
||||
foreach ($arr as $kk => $vv) {
|
||||
$cart_arr[] = $vv;
|
||||
}
|
||||
$order_id[] = $v['id'];
|
||||
}
|
||||
$where = ['is_pay' => 1, 'is_fail' => 0];
|
||||
$cart_select = Cart::whereIn('cart_id', $cart_arr)->where($where)->field('goods_id as goods,cart_num')->select()->toArray();
|
||||
if (empty($cart_select)) {
|
||||
self::setError('购物车为空');
|
||||
return false;
|
||||
}
|
||||
/** 计算价格 */
|
||||
foreach ($cart_select as $k => $v) {
|
||||
$sell = Goods::where(['id' => $v['goods']])->value('sell');
|
||||
$cart_select[$k]['total'] = bcmul($v['cart_num'], $sell, 2);
|
||||
$cart_select[$k]['price'] = $sell;
|
||||
$cart_select[$k]['is_mer'] = 2;
|
||||
}
|
||||
$order = [
|
||||
'time' => time(),
|
||||
'number' => static::getNewOrderId('CG'),
|
||||
'total' => array_sum(array_column($cart_select, 'total')),
|
||||
'pay_type' => $params['pay_type'] ?? 0,
|
||||
'cart_id' => implode(',', $cart_arr),
|
||||
'order_arr' => implode(',', $order_id)
|
||||
];
|
||||
return ['order' => $order, 'cart_list' => $cart_select];
|
||||
}
|
||||
/**
|
||||
* 创建购货订单
|
||||
* @return Object|bool
|
||||
*/
|
||||
static public function createOpurchaseOrder($user = null, $params = [])
|
||||
{
|
||||
|
||||
$orderInfo = self::cartIdByPurchaseOrderInfo($user, $params);
|
||||
if (!$orderInfo) {
|
||||
return false;
|
||||
}
|
||||
$_order = $orderInfo['order'];
|
||||
|
||||
$_order['merchant'] = getenv('OPERATED');
|
||||
$_order['money'] = $_order['total'];
|
||||
$_order['actual'] = $_order['total'];
|
||||
$_order['paid'] = 1;
|
||||
$_order['is_mer'] = 2;
|
||||
Db::startTrans();
|
||||
try {
|
||||
Opurchaseclass::create([]);
|
||||
$order = Opurchaseclass::create($_order);
|
||||
|
||||
$goods_list = $orderInfo['cart_list'];
|
||||
foreach ($goods_list as $k => $v) {
|
||||
$goods_list[$k]['nums'] = $v['cart_num'];
|
||||
$goods_list[$k]['pid'] = $order->id;
|
||||
}
|
||||
(new Opurchaseinfo())->saveAll($goods_list);
|
||||
$order_arr = explode(',', $_order['order_arr']);
|
||||
Opurchaseclass::where('id', 'in', $order_arr)->update(['is_opurchase' => 1]);
|
||||
Db::commit();
|
||||
return true;
|
||||
return $order;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
@ -46,43 +110,6 @@ class OpurchaseclassLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑采购订单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/04/27 11:26
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
Opurchaseclass::where('id', $params['id'])->update([]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除采购订单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/04/27 11:26
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return Opurchaseclass::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取采购订单详情
|
||||
* @param $params
|
||||
@ -217,4 +244,19 @@ class OpurchaseclassLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取订单号
|
||||
* @param $type
|
||||
* @return string
|
||||
* @author likeadmin
|
||||
* @date 2021/7/28 17:05
|
||||
*/
|
||||
static public function getNewOrderId($type)
|
||||
{
|
||||
list($msec, $sec) = explode(' ', microtime());
|
||||
$msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
|
||||
$orderId = $type . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
|
||||
return $orderId;
|
||||
}
|
||||
}
|
||||
|
@ -13,12 +13,17 @@ class OrderEnum
|
||||
* @ORDER_HANDLING_FEES 订单手续费
|
||||
* @MERCHANT_ORDER_PAY 商户订单支付
|
||||
* @PLATFORM_ORDER_OBTAINS 平台订单获得
|
||||
* @SUPPLIER_ORDER_OBTAINS 供应链订单获得
|
||||
* @MERCHANT_ORDER_PAY 平台订单支付
|
||||
*/
|
||||
const USER_ORDER_PAY = 1;
|
||||
const MERCHANT_ORDER_OBTAINS = 2;
|
||||
const ORDER_HANDLING_FEES = 3;
|
||||
const MERCHANT_ORDER_PAY = 4;
|
||||
const PLATFORM_ORDER_OBTAINS = 5;
|
||||
const SUPPLIER_ORDER_OBTAINS = 6;
|
||||
const PLATFORM_ORDER_PAY = 7;
|
||||
|
||||
|
||||
/**
|
||||
* 收入支出类型
|
||||
@ -33,10 +38,12 @@ class OrderEnum
|
||||
* @USER 用户
|
||||
* @MERCHANT 商户
|
||||
* @PLATFORM 平台
|
||||
* @SUPPLIER 供应链
|
||||
*/
|
||||
const USER =0;
|
||||
const MERCHANT =1;
|
||||
const PLATFORM =2;
|
||||
const SUPPLIER =3;
|
||||
|
||||
|
||||
|
||||
|
@ -154,4 +154,42 @@ class PayNotifyLogic extends BaseLogic
|
||||
];
|
||||
(new FinancialRecord())->saveAll($record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台采购订单支付成功
|
||||
*/
|
||||
public static function operated($orderSn, $extra = [])
|
||||
{
|
||||
$order = Opurchaseclass::where('number', $orderSn)->findOrEmpty();
|
||||
$order_arr=explode(',',$order['order_arr']);
|
||||
(new FinancialRecord())->where('order_id','in',$order_arr)->update(['status' => 1]);
|
||||
$time=time();
|
||||
//平台支出流水
|
||||
$record[] = [
|
||||
'financial_record_sn' => $time,
|
||||
'order_id' => $order['id'],
|
||||
'number_sn' => $order['number'],
|
||||
'user_id' => $order['uid'],
|
||||
'financial_type' => OrderEnum::PLATFORM_ORDER_PAY,
|
||||
'financial_pm' => OrderEnum::EXPENDITURE,
|
||||
'number' => $order['actual'],
|
||||
'status' => 1,
|
||||
'type' => OrderEnum::PLATFORM,
|
||||
'mer_id' => getenv('OPERATED'),
|
||||
];
|
||||
// //平台获得流水
|
||||
// $record[] = [
|
||||
// 'financial_record_sn' => $time,
|
||||
// 'order_id' => $order['id'],
|
||||
// 'number_sn' => $order['number'],
|
||||
// 'user_id' => $order['uid'],
|
||||
// 'financial_type' => OrderEnum::PLATFORM_ORDER_OBTAINS,
|
||||
// 'financial_pm' => OrderEnum::INCOME,
|
||||
// 'number' => $order['actual'],
|
||||
// 'status' => 1,
|
||||
// 'type' => OrderEnum::PLATFORM,
|
||||
// 'mer_id' => $order['merchant'],
|
||||
// ];
|
||||
(new FinancialRecord())->saveAll($record);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user