commit
c07e44109d
@ -1,11 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\purchase_order;
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\purchase_order\PurchaseOrderLists;
|
||||
use app\admin\lists\purchase_order_info\PurchaseOrderInfoLists;
|
||||
use app\admin\lists\store_order\StoreOrderLists;
|
||||
use app\admin\logic\purchase_order\PurchaseOrderLogic;
|
||||
use app\common\model\purchase_order\PurchaseOrder;
|
||||
|
||||
class PurchaseOrderController extends BaseAdminController{
|
||||
class PurchaseOrderController extends BaseAdminController
|
||||
{
|
||||
|
||||
public function lists()
|
||||
{
|
||||
@ -18,14 +23,20 @@ class PurchaseOrderController extends BaseAdminController{
|
||||
/**
|
||||
* 合并今日商户订单
|
||||
*/
|
||||
public function add(){
|
||||
PurchaseOrderLogic::StoreTodayOrder();
|
||||
public function add()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
PurchaseOrderLogic::mergeOrder($data);
|
||||
if (PurchaseOrderLogic::hasError()) {
|
||||
return $this->fail(PurchaseOrderLogic::getError());
|
||||
}
|
||||
return $this->success('合并成功');
|
||||
}
|
||||
/**
|
||||
* 合并今日平台订单
|
||||
*/
|
||||
public function platform(){
|
||||
public function platform()
|
||||
{
|
||||
PurchaseOrderLogic::platformTodayOrder();
|
||||
return $this->success('合并成功');
|
||||
}
|
||||
@ -33,7 +44,8 @@ class PurchaseOrderController extends BaseAdminController{
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
public function detail(){
|
||||
public function detail()
|
||||
{
|
||||
$id = $this->request->get('id');
|
||||
$res = PurchaseOrderLogic::detail($id);
|
||||
return $this->data($res);
|
||||
|
@ -28,7 +28,7 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => [],
|
||||
'=' => ['order_id'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc
|
||||
->select()->each(function($item){
|
||||
$find=StoreProduct::where('id',$item->product_id)->find();
|
||||
$item->store_name=$find->store_name;
|
||||
$item->store_info=$find->store_info;
|
||||
$item->image=$find->image;
|
||||
$item->unit_name=StoreProductUnit::where('id',$item->unit)->value('name');
|
||||
if($item->is_buyer==1){
|
||||
|
@ -30,7 +30,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['order_id','store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff'],
|
||||
'=' => ['order_id','store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff','is_merge'],
|
||||
'between_time' => 'create_time'
|
||||
];
|
||||
}
|
||||
@ -62,7 +62,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$query->whereIn('status', $status);
|
||||
}
|
||||
})
|
||||
->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_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'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
|
@ -6,8 +6,10 @@ namespace app\admin\logic\purchase_order;
|
||||
use app\common\model\purchase_order\PurchaseOrder;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\purchase_order_info\PurchaseOrderInfo;
|
||||
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use think\facade\Db;
|
||||
|
||||
@ -20,6 +22,117 @@ use think\facade\Db;
|
||||
class PurchaseOrderLogic extends BaseLogic
|
||||
{
|
||||
|
||||
public static function mergeOrder($params)
|
||||
{
|
||||
$oid_arr = [];
|
||||
$store_arr = [];
|
||||
$purchaseOrderInfo = new PurchaseOrderInfo();
|
||||
|
||||
foreach ($params as $k => $v) {
|
||||
$oid_arr[] = $v['oid'];
|
||||
$store_arr[] = $v['store_id'];
|
||||
}
|
||||
$store_arr = array_unique($store_arr);
|
||||
|
||||
// Db::startTrans();
|
||||
// try {
|
||||
$price = StoreOrder::whereIn('id', $oid_arr)->whereIn('store_id', $store_arr)->group('store_id')->field('store_id,SUM(pay_price) as pay_price,SUM(total_price) as total_price')->select()->toArray();
|
||||
$purchase_arr = [];
|
||||
$order_arr = [];
|
||||
$total_price = 0;
|
||||
$pay_price = 0;
|
||||
foreach ($price as $k => $v) {
|
||||
foreach($params as $key => $value){
|
||||
if($value['store_id']==$v['store_id']){
|
||||
$order_arr[] = $value['oid'];
|
||||
}
|
||||
}
|
||||
|
||||
$total_price += $v['total_price'];
|
||||
$pay_price += $v['pay_price'];
|
||||
$data = [
|
||||
'store_id' => $v['store_id'],
|
||||
'order_arr' => json_encode($order_arr),
|
||||
'order_id' => getNewOrderId('CG'),
|
||||
'total' => $v['total_price'],
|
||||
'actual' => $v['pay_price'],
|
||||
'money' => $v['pay_price'],
|
||||
'paid' => 1,
|
||||
'is_mer' => 1,
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
//创建门店合计订单
|
||||
$res = PurchaseOrder::create($data);
|
||||
$purchase_arr[] = ['id'=>$res['id'],'store_id'=>$v['store_id']];
|
||||
$purchase_id[] =$res['id'];
|
||||
}
|
||||
$info = StoreOrderCartInfo::where('oid', 'in', $order_arr)->field('store_id, product_id,price,SUM(total_price) as total_price, SUM(cart_num) as cart_num')->group('store_id, product_id')->select()->toArray();
|
||||
//创建门店合计商品
|
||||
foreach($purchase_arr as $k=>$v){
|
||||
foreach ($info as $item) {
|
||||
if($v['store_id']==$item['store_id']){
|
||||
$arr['oid'] = $v['id'];
|
||||
$arr['store_id'] = $item['store_id'];
|
||||
$arr['product_id'] = $item['product_id'];
|
||||
$arr['price'] = $item['price'];
|
||||
$arr['total_price'] = $item['total_price'];
|
||||
$arr['cart_num'] = $item['cart_num'];
|
||||
$arr['status'] = 1;
|
||||
$purchase_order_info[] = $arr;
|
||||
}
|
||||
}
|
||||
}
|
||||
$purchaseOrderInfo->saveAll($purchase_order_info);
|
||||
//---------------生成平台订单-----------------
|
||||
$data = [
|
||||
'store_id' => 0,
|
||||
'store_arr' => json_encode($store_arr),
|
||||
'order_arr' => json_encode($purchase_id),
|
||||
'order_id' => getNewOrderId('PT'),
|
||||
'total' => $total_price,
|
||||
'actual' => $pay_price,
|
||||
'money' => $pay_price,
|
||||
'paid' => 1,
|
||||
'is_mer' => 2,
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
$res = PurchaseOrder::create($data);
|
||||
$info = PurchaseOrderInfo::where('oid', 'in', $purchase_id)->field('store_id, product_id,price,SUM(total_price) as total_price, SUM(cart_num) as cart_num')->group('store_id, product_id')->select();
|
||||
$purchase_order_info_two=[];
|
||||
foreach ($info as $item) {
|
||||
$arr['oid'] = $res['id'];
|
||||
$arr['store_id'] = $item['store_id'];
|
||||
$arr['product_id'] = $item['product_id'];
|
||||
$arr['price'] = $item['price'];
|
||||
$arr['total_price'] = $item['total_price'];
|
||||
$arr['cart_num'] = $item['cart_num'];
|
||||
$arr['status'] = 1;
|
||||
$purchase_order_info_two[] = $arr;
|
||||
}
|
||||
$purchaseOrderInfo->saveAll($purchase_order_info_two);
|
||||
$productOffer = [];
|
||||
foreach ($info as $item) {
|
||||
$arr['order_id'] = $res['id'];
|
||||
$arr['product_id'] = $item['product_id'];
|
||||
$arr['price'] = $item['price'];
|
||||
$arr['total_price'] = $item['total_price'];
|
||||
$arr['need_num'] = $item['cart_num'];
|
||||
$arr['unit'] = StoreProduct::where('id', $item['product_id'])->value('unit');
|
||||
$productOffer[] = $arr;
|
||||
}
|
||||
$purchaseProductOffer = new PurchaseProductOffer();
|
||||
$purchaseProductOffer->saveAll($productOffer);
|
||||
// StoreOrder::whereIn('id', $oid_arr)->update(['is_merge' => 1]);
|
||||
// Db::commit();
|
||||
// return true;
|
||||
// } catch (\Throwable $e) {
|
||||
// Db::rollback();
|
||||
// self::setError($e->getMessage());
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 合并今日商户订单
|
||||
@ -118,7 +231,6 @@ class PurchaseOrderLogic extends BaseLogic
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
d($e);
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
@ -293,8 +293,8 @@ class UserController extends BaseApiController
|
||||
*/
|
||||
public function cash_info()
|
||||
{
|
||||
$info = User::where('id', $this->userId)->field('id,now_money,id_card')->find();
|
||||
$info['notes'] = '提现金额需大于1元,提现到微信零钱,并财务审核,审核通过后,提现金额将自动到账';
|
||||
$info = User::where('id', $this->userId)->field('id,real_name,mobile,now_money,id_card')->find();
|
||||
$info['notes'] = '提现金额需大于1元,提现到微信零钱,并财务审核,审核通过后,提现金额将自动到账。若本月提现超过800元,将产生个人所得税款,具体税率及金额根据《中华人民共和国个人所得税法》第二条、第三条、第六条规定扣缴。';
|
||||
$info['extract_price'] =StoreExtract::where('uid',$this->userId)->sum('extract_price');
|
||||
return $this->data($info);
|
||||
}
|
||||
@ -312,6 +312,9 @@ class UserController extends BaseApiController
|
||||
if ($money < 1) {
|
||||
return $this->fail('提现金额不能小于1元');
|
||||
}
|
||||
if ($find['id_card']=='') {
|
||||
return $this->fail('请先完成身份认证');
|
||||
}
|
||||
$data['uid'] = $this->userId;
|
||||
$data['create_time'] = time();
|
||||
$data['status'] = 0;
|
||||
@ -358,9 +361,9 @@ class UserController extends BaseApiController
|
||||
* 更新身份证号
|
||||
*/
|
||||
public function update_id_card(){
|
||||
$id_card = $this->request->post('id_card');
|
||||
if($id_card){
|
||||
User::where('id',$this->userId)->update(['id_card'=>$id_card]);
|
||||
$data= (new UserValidate())->post()->goCheck('card');
|
||||
if($data){
|
||||
User::where('id',$this->userId)->update(['id_card'=>$data['id_card'],'real_name'=>$data['real_name'],'nickname'=>$data['real_name']]);
|
||||
return $this->success('设置成功');
|
||||
}
|
||||
return $this->fail('请输入身份证号');
|
||||
|
@ -24,6 +24,8 @@ class UserValidate extends BaseValidate
|
||||
'rePassword' => 'require|requireWith:password|confirm:password',
|
||||
'type' => 'require',
|
||||
'account' => 'require',
|
||||
'real_name' => 'require',
|
||||
'id_card' => 'require|idCard',
|
||||
|
||||
];
|
||||
|
||||
@ -36,6 +38,8 @@ class UserValidate extends BaseValidate
|
||||
'password.require' => '密码缺失',
|
||||
'rePassword.require' => '确认密码缺失',
|
||||
'type' => '查询类型',
|
||||
'id_card' => '身份证格式错误',
|
||||
'real_name' => '姓名不能为空',
|
||||
];
|
||||
|
||||
|
||||
@ -49,6 +53,11 @@ class UserValidate extends BaseValidate
|
||||
{
|
||||
return $this->only(['type']);
|
||||
|
||||
}
|
||||
public function sceneCard()
|
||||
{
|
||||
return $this->only(['id_card','real_name']);
|
||||
|
||||
}
|
||||
|
||||
//设置/更新密码
|
||||
|
@ -17,6 +17,6 @@ class PurchaseOrder extends BaseModel
|
||||
use SoftDelete;
|
||||
protected $name = 'purchase_order';
|
||||
protected $deleteTime = 'delete_time';
|
||||
protected $json = ['order_arr'];
|
||||
protected $json = ['order_arr','store_arr'];
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user