This commit is contained in:
shengchanzhe 2023-12-15 15:32:05 +08:00
parent 9616494680
commit 39a1e6250d
9 changed files with 3392 additions and 6 deletions

View File

@ -0,0 +1,764 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\store\order;
use app\common\dao\BaseDao;
use app\common\model\store\order\StoreOtherGroupOrder;
use app\common\model\store\order\StoreOrderOther;
use app\common\model\store\order\StoreOrderProductOther;
use app\common\model\store\order\StoreOrderStatusOther;
use app\common\repositories\store\order\StoreOrderStatusRepository;
use app\common\repositories\store\product\ProductAssistSetRepository;
use app\common\repositories\store\product\ProductGroupBuyingRepository;
use think\db\BaseQuery;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Db;
use think\Model;
/**
* Class StoreOrderDao
* @package app\common\dao\store\order
* @author xaboy
* @day 2020/6/8
*/
class StoreOrderOtherDao extends BaseDao
{
//订单状态0待发货1待收货2待评价3已完成 9: 拼团中 10: 待付尾款 11:尾款超时未付 -1已退款
const ORDER_STATUS_BE_SHIPPED = 0;
const ORDER_STATUS_BE_RECEIVE = 1;
const ORDER_STATUS_REPLY = 2;
const ORDER_STATUS_SUCCESS = 3;
const ORDER_STATUS_SPELL = 9;
const ORDER_STATUS_TAIL = 10;
const ORDER_STATUS_TAIL_FAIL = 11;
const ORDER_STATUS_REFUND = -1;
/**
* @return string
* @author xaboy
* @day 2020/6/8
*/
protected function getModel(): string
{
return StoreOrderOther::class;
}
/**
* @param array $where
* @param int $sysDel
* @return BaseQuery
* @author xaboyCRMEB
* @day 2020/6/16
*/
public function search(array $where, $sysDel = 0)
{
$query = StoreOrderOther::hasWhere('merchant', function ($query) use ($where) {
if (isset($where['is_trader']) && $where['is_trader'] !== '') {
$query->where('is_trader', $where['is_trader']);
}
$query->where('is_del', 0);
});
$query->when(($sysDel !== null), function ($query) use ($sysDel) {
$query->where('is_system_del', $sysDel);
})
->when(isset($where['order_type']) && $where['order_type'] >= 0 && $where['order_type'] !== '', function ($query) use ($where) {
if ($where['order_type'] == 2) {
$query->where('is_virtual', 1);
} else if ($where['order_type'] == 0) { //实体发货订单
$query->where('order_type', 0)->where('is_virtual', 0);
} else if ($where['order_type'] == 3) { //发货订单
$query->where('order_type', 0);
} else {
$query->where('order_type', $where['order_type']);
}
})
->when(isset($where['activity_type']) && $where['activity_type'] != '', function ($query) use ($where) {
$query->where('activity_type', $where['activity_type']);
})
->when(isset($where['product_type']) && $where['product_type'] != '', function ($query) use ($where) {
$query->where('activity_type', $where['product_type']);
})
->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
// 12表示信用购 先货后款
switch ($where['status']) {
case 0:
$query->whereIn('StoreOrderOther.status', [0, 9, 12]);
break;
case -2:
$query->where('StoreOrderOther.paid', 1)->whereNotIn('StoreOrderOther.status', [10, 11]);
break;
case 10:
$query->where('StoreOrderOther.paid', 1)->whereIn('StoreOrderOther.status', [10, 11]);
break;
case 2:
$query->where('StoreOrderOther.paid', 1)->where('StoreOrderOther.status', $where['status'])->where('pay_type', '<>', StoreGroupOrder::PAY_TYPE_CREDIT_BUY);
break;
case 20:
$query->where('StoreOrderOther.paid', 1)->whereIn('StoreOrderOther.status', [2, 3]);
break;
default:
$query->where('StoreOrderOther.status', $where['status']);
break;
}
})
->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
$query->where('StoreOrderOther.uid', $where['uid']);
})
->when(isset($where['is_user']) && $where['is_user'] !== 0, function ($query) use ($where) {
$query->where(function ($query) {
$query->where('order_type', 0)->whereOr(function ($query) {
$query->where('order_type', 1)->where('main_id', 0);
});
});
})
//待核销订单
->when(isset($where['is_verify']) && $where['is_verify'], function ($query) use ($where) {
$query->where('StoreOrderOther.order_type', 1)->where('StoreOrderOther.status', 0);
})
->when(isset($where['pay_type']) && $where['pay_type'] !== '', function ($query) use ($where) {
$query->where('StoreOrderOther.pay_type', $where['pay_type']);
})
->when(isset($where['order_ids']) && $where['order_ids'] !== '', function ($query) use ($where) {
$query->whereIn('order_id', $where['order_ids']);
})
->when(isset($where['order_id']) && $where['order_id'] !== '', function ($query) use ($where) {
if (is_array($where['order_id'])) {
$query->whereIn('order_id', $where['order_id']);
} else {
$query->where('order_id', $where['order_id']);
}
})
->when(isset($where['take_order']) && $where['take_order'] != '', function ($query) use ($where) {
$query->where('order_type', 1)->whereNotNull('verify_time');
})
->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
$query->where('StoreOrderOther.mer_id', $where['mer_id']);
})
->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
getModelTime($query, $where['date'], 'StoreOrderOther.create_time');
})
->when(isset($where['pay_time']) && $where['pay_time'] !== '', function ($query) use ($where) {
getModelTime($query, $where['pay_time'], 'StoreOrderOther.pay_time');
})
->when(isset($where['verify_date']) && $where['verify_date'] !== '', function ($query) use ($where) {
getModelTime($query, $where['verify_date'], 'verify_time');
})
->when(isset($where['order_sn']) && $where['order_sn'] !== '', function ($query) use ($where) {
$query->where('order_sn', 'like', '%' . $where['order_sn'] . '%');
})
->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
$query->where('StoreOrderOther.paid', $where['paid']);
})
->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
$query->where('StoreOrderOther.is_del', $where['is_del']);
})
->when(isset($where['service_id']) && $where['service_id'] !== '', function ($query) use ($where) {
$query->where('service_id', $where['service_id']);
})
->when(isset($where['username']) && $where['username'] !== '', function ($query) use ($where) {
$query->join('User U', 'StoreOrderOther.uid = U.uid')
->where(function ($query) use ($where) {
$query->where('nickname', 'like', "%{$where['username']}%")
->whereOr('phone', 'like', "%{$where['username']}%")
->whereOr('user_phone', 'like', "%{$where['username']}%");
});
})
->when(isset($where['store_name']) && $where['store_name'] !== '', function ($query) use ($where) {
$orderId = StoreOrderProductOther::alias('op')
->join('storeProduct sp', 'op.product_id = sp.product_id')
->whereLike('store_name', "%{$where['store_name']}%")
->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''), function ($query) use ($where) {
$query->where('mer_id', $where['mer_id']);
})->column('order_id');
$query->whereIn('order_id', $orderId ?: '');
})
->when(isset($where['search']) && $where['search'] !== '', function ($query) use ($where) {
$orderId = StoreOrderProductOther::alias('op')
->join('storeProduct sp', 'op.product_id = sp.product_id')
->whereLike('store_name', "%{$where['search']}%")
->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''), function ($query) use ($where) {
$query->where('mer_id', $where['mer_id']);
})->column('order_id');
$query->where(function ($query) use ($orderId, $where) {
$query->whereIn('order_id', $orderId ? $orderId : '')
->whereOr('order_sn', 'like', "%{$where['search']}%")
->whereOr('user_phone', 'like', "%{$where['search']}%");
});
})
->when(isset($where['order_search']) && $where['order_search'] !== '', function ($query) use ($where) {
$query->where('order_sn', 'like', '%' . $where['order_search'] . '%')->whereOr('user_phone', $where['order_search']);
})
->when(isset($where['group_order_sn']) && $where['group_order_sn'] !== '', function ($query) use ($where) {
$query->join('StoreGroupOrder GO', 'StoreOrderOther.group_order_id = GStoreOrderOther.group_order_id')->where('group_order_sn', $where['group_order_sn']);
})
->when(isset($where['keywords']) && $where['keywords'] !== '', function ($query) use ($where) {
$query->where(function ($query) use ($where) {
$query->whereLike('StoreOrderOther.real_name|StoreOrderOther.user_phone|order_sn', "%" . $where['keywords'] . "%");
});
})
->when(isset($where['reconciliation_type']) && $where['reconciliation_type'] !== '', function ($query) use ($where) {
$query->when($where['reconciliation_type'], function ($query) use ($where) {
$query->where('reconciliation_id', '<>', 0);
}, function ($query) use ($where) {
$query->where('reconciliation_id', 0);
});
})->order('StoreOrderOther.create_time DESC');
return $query;
}
/**
* @param $id
* @param $uid
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020/6/11
*/
public function userOrder($id, $uid)
{
return StoreOrderOther::getDB()->where('order_id', $id)->where('uid', $uid)->where('is_del', 0)->where('paid', 1)->where('is_system_del', 0)->find();
}
/**
* @param array $where
* @param $ids
* @return BaseQuery
* @author xaboy
* @day 2020/6/26
*/
public function usersOrderQuery(array $where, $ids, $uid)
{
return StoreOrderOther::getDB()->where(function ($query) use ($uid, $ids) {
$query->whereIn('uid', $ids)->whereOr(function ($query) use ($uid) {
if ($uid) {
$query->where('uid', $uid)->where('is_selfbuy', 1);
}
});
})->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
getModelTime($query, $where['date'], 'pay_time');
})->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
$query->whereLike('order_id|order_sn', "%{$where['keyword']}%");
})->where('paid', 1)->order('pay_time DESC');
}
/**
* @param $field
* @param $value
* @param int|null $except
* @return bool
* @author xaboy
* @day 2020/6/11
*/
public function fieldExists($field, $value, ?int $except = null): bool
{
return ($this->getModel()::getDB())->when($except, function ($query) use ($field, $except) {
$query->where($field, '<>', $except);
})->where($field, $value)->count() > 0;
}
/**
* @param $id
* @return mixed
* @author xaboy
* @day 2020/6/12
*/
public function getMerId($id)
{
return StoreOrderOther::getDB()->where('order_id', $id)->value('mer_id');
}
/**
* @param array $where
* @return bool
* @author Qinii
* @day 2020-06-12
*/
public function merFieldExists(array $where)
{
return ($this->getModel()::getDB())->where($where)->count() > 0;
}
/**
* TODO
* @param $reconciliation_id
* @return mixed
* @author Qinii
* @day 2020-06-15
*/
public function reconciliationUpdate($reconciliation_id)
{
return ($this->getModel()::getDB())->whereIn('reconciliation_id', $reconciliation_id)->update(['reconciliation_id' => 0]);
}
public function dayOrderNum($day, $merId = null)
{
return StoreOrderOther::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->when($day, function ($query, $day) {
getModelTime($query, $day, 'pay_time');
})->count();
}
public function dayOrderPrice($day, $merId = null)
{
return getModelTime(StoreOrderOther::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
}), $day, 'pay_time')->sum('pay_price');
}
public function dateOrderPrice($date, $merId = null)
{
return StoreOrderOther::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->when($date, function ($query, $date) {
getModelTime($query, $date, 'pay_time');
})->sum('pay_price');
}
public function dateOrderNum($date, $merId = null)
{
return StoreOrderOther::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->when($date, function ($query, $date) {
getModelTime($query, $date, 'pay_time');
})->count();
}
public function dayOrderUserNum($day, $merId = null)
{
return StoreOrderOther::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->when($day, function ($query, $day) {
getModelTime($query, $day, 'pay_time');
})->group('uid')->count();
}
public function orderUserNum($date, $paid = null, $merId = null)
{
return StoreOrderOther::getDB()->when($paid, function ($query, $paid) {
$query->where('paid', $paid);
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->when($date, function ($query, $date) use ($paid) {
if (!$paid) {
getModelTime($query, $date);
// $query->where(function ($query) use ($date) {
// $query->where(function ($query) use ($date) {
// $query->where('paid', 1);
// getModelTime($query, $date, 'pay_time');
// })->whereOr(function ($query) use ($date) {
// $query->where('paid', 0);
// getModelTime($query, $date);
// });
// });
} else
getModelTime($query, $date, 'pay_time');
})->group('uid')->count();
}
public function orderUserGroup($date, $paid = null, $merId = null)
{
return StoreOrderOther::getDB()->when($paid, function ($query, $paid) {
$query->where('paid', $paid);
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->when($date, function ($query, $date) {
getModelTime($query, $date, 'pay_time');
})->group('uid')->field(Db::raw('uid,sum(pay_price) as pay_price,count(order_id) as total'))->select();
}
public function oldUserNum(array $ids, $merId = null)
{
return StoreOrderOther::getDB()->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->whereIn('uid', $ids)->where('paid', 1)->group('uid')->count();
}
public function oldUserIds(array $ids, $merId = null)
{
return StoreOrderOther::getDB()->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->whereIn('uid', $ids)->where('paid', 1)->group('uid')->column('uid');
}
public function orderPrice($date, $paid = null, $merId = null)
{
return StoreOrderOther::getDB()->when($paid, function ($query, $paid) {
$query->where('paid', $paid);
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->when($date, function ($query, $date) use ($paid) {
if (!$paid) {
$query->where(function ($query) use ($date) {
$query->where(function ($query) use ($date) {
$query->where('paid', 1);
getModelTime($query, $date, 'pay_time');
})->whereOr(function ($query) use ($date) {
$query->where('paid', 0);
getModelTime($query, $date);
});
});
} else
getModelTime($query, $date, 'pay_time');
})->sum('pay_price');
}
public function orderGroupNum($date, $merId = null)
{
$field = Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m-%d\') as `day`');
if ($date == 'year') {
$field = Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m\') as `day`');
}
$query = StoreOrderOther::getDB()->field($field)
->where('paid', 1)->when($date, function ($query, $date) {
getModelTime($query, $date, 'pay_time');
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
});
return $query->order('pay_time ASC')->group('day')->select();
}
public function orderGroupNumPage($where, $page, $limit, $merId = null)
{
return StoreOrderOther::getDB()->when(isset($where['dateRange']), function ($query) use ($where) {
getModelTime($query, date('Y/m/d 00:00:00', $where['dateRange']['start']) . '-' . date('Y/m/d 00:00:00', $where['dateRange']['stop']), 'pay_time');
})->field(
Db::raw('status,sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m-%d\') as `day`')
)
->where('paid', 1)->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->order('pay_time DESC')->page($page, $limit)->group('day')->select()->each(function ($item) use ($merId) {
$pay_time = explode(' ', $item['pay_time']);
$item->settlement_price = Db::name('store_order')
->whereIn('status', [2, 3])
->where('mer_id', $merId)
->whereDay('pay_time', $pay_time[0])
->sum('pay_price');
});
}
public function dayOrderPriceGroup($date, $merId = null)
{
return StoreOrderOther::getDB()->field(Db::raw('sum(pay_price) as price, from_unixtime(unix_timestamp(pay_time),\'%H:%i\') as time'))
->where('paid', 1)->when($date, function ($query, $date) {
getModelTime($query, $date, 'pay_time');
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->group('time')->select();
}
public function dayOrderNumGroup($date, $merId = null)
{
return StoreOrderOther::getDB()->field(Db::raw('count(*) as total, from_unixtime(unix_timestamp(pay_time),\'%H:%i\') as time'))
->where('paid', 1)->when($date, function ($query, $date) {
getModelTime($query, $date, 'pay_time');
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->group('time')->select();
}
public function dayOrderUserGroup($date, $merId = null)
{
return StoreOrderOther::getDB()->field(Db::raw('count(DISTINCT uid) as total, from_unixtime(unix_timestamp(pay_time),\'%H:%i\') as time'))
->where('paid', 1)->when($date, function ($query, $date) {
getModelTime($query, $date, 'pay_time');
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->group('time')->select();
}
/**
* 获取当前时间到指定时间的支付金额 管理员
* @param string $start 开始时间
* @param string $stop 结束时间
* @return mixed
*/
public function chartTimePrice($start, $stop, $merId = null)
{
return StoreOrderOther::getDB()->where('paid', 1)
->where('pay_time', '>=', $start)
->where('pay_time', '<', $stop)
->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})
->field('sum(pay_price) as num,FROM_UNIXTIME(unix_timestamp(pay_time), \'%Y-%m-%d\') as time')
->group('time')
->order('pay_time ASC')->select()->toArray();
}
/**
* @param $date
* @param null $merId
* @return mixed
*/
public function chartTimeNum($date, $merId = null)
{
return StoreOrderOther::getDB()->where('paid', 1)->when($date, function ($query) use ($date) {
getModelTime($query, $date, 'pay_time');
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->field('count(order_id) as num,FROM_UNIXTIME(unix_timestamp(pay_time), \'%Y-%m-%d\') as time')
->group('time')
->order('pay_time ASC')->select()->toArray();
}
/**
* @param $end
* @return mixed
* @author xaboy
* @day 2020/9/16
*/
public function getFinishTimeoutIds($end)
{
return StoreOrderStatusOther::getDB()->alias('A')->leftJoin('StoreOrderOther B', 'A.order_id = B.order_id')
->where('A.change_type', 'take')
->where('A.change_time', '<', $end)->where('B.paid', 1)->where('B.status', 2)->where('B.pay_type', '<>', StoreGroupOrder::PAY_TYPE_CREDIT_BUY)
->column('A.order_id');
}
/**
* TODO 参与人数
* @param array $data
* @param int|null $uid
* @return BaseQuery
* @author Qinii
* @day 2020-11-11
*/
public function getTattendCount(array $data, ?int $uid)
{
$query = StoreOrderOther::hasWhere('orderProduct', function ($query) use ($data, $uid) {
$query->when(isset($data['activity_id']), function ($query) use ($data) {
$query->where('activity_id', $data['activity_id']);
})
->when(isset($data['product_sku']), function ($query) use ($data) {
$query->where('product_sku', $data['product_sku']);
})
->when(isset($data['product_id']), function ($query) use ($data) {
$query->where('product_id', $data['product_id']);
})
->when(isset($data['exsits_id']), function ($query) use ($data) {
switch ($data['product_type']) {
case 3:
$make = app()->make(ProductAssistSetRepository::class);
$id = 'product_assist_id';
break;
case 4:
$make = app()->make(ProductGroupBuyingRepository::class);
$id = 'product_group_id';
break;
}
$where = [$id => $data['exsits_id']];
$activity_id = $make->getSearch($where)->column($make->getPk());
if ($activity_id) {
$id = array_unique($activity_id);
$query->where('activity_id', 'in', $id);
} else {
$query->where('activity_id', '<', 0);
}
})
->where('product_type', $data['product_type']);
if ($uid) $query->where('uid', $uid);
});
$query->where('activity_type', $data['product_type']);
switch ($data['product_type']) {
case 0:
$query->where(function ($query) {
$query->where(function ($query) {
$query->where('paid', 1);
})->whereOr(function ($query) {
$query->where('paid', 0)->where('is_del', 0);
});
});
break;
case 1: //秒杀
$query->where(function ($query) {
$query->where(function ($query) {
$query->where('paid', 1);
})->whereOr(function ($query) {
$query->where('paid', 0)->where('is_del', 0);
});
})->when(isset($data['day']), function ($query) use ($data) {
$query->whereDay('StoreOrderOther.create_time', $data['day']);
});
break;
case 2: //预售
/**
* 第一阶段参与人数:所有人
* 第二阶段参与人数:支付了第一阶段
*/
//第二阶段
if ($data['type'] == 1) {
$query->where(function ($query) {
$query->where('paid', 1)->whereOr(function ($query) {
$query->where('paid', 0)->where('is_del', 0);
});
});
}
if ($data['type'] == 2) $query->where('paid', 1)->where('status', 'in', [0, 1, 2, 3, -1]);
break;
case 3: //助力
$query->where(function ($query) {
$query->where('paid', 1)->whereOr(function ($query) {
$query->where('paid', 0)->where('is_del', 0);
});
});
break;
case 4: //
$query->where(function ($query) {
$query->where('paid', 1)->whereOr(function ($query) {
$query->where('paid', 0)->where('is_del', 0);
})
->where('status', '>', -1);
});
break;
}
return $query;
}
/**
* 未使用
* TODO 成功支付人数
* @param int $productType
* @param int $activityId
* @param int|null $uid
* @param int|null $status
* @author Qinii
* @day 2020-10-30
*/
public function getTattendSuccessCount($data, ?int $uid)
{
$query = StoreOrderOther::hasWhere('orderProduct', function ($query) use ($data, $uid) {
$query->when(isset($data['activity_id']), function ($query) use ($data) {
$query->where('activity_id', $data['activity_id']);
})
->when(isset($data['product_sku']), function ($query) use ($data) {
$query->where('product_sku', $data['product_sku']);
})
->when(isset($data['product_id']), function ($query) use ($data) {
$query->where('product_id', $data['product_id']);
})
->when(isset($data['exsits_id']), function ($query) use ($data) {
switch ($data['product_type']) {
case 3:
$make = app()->make(ProductAssistSetRepository::class);
$id = 'product_assist_id';
break;
case 4:
$make = app()->make(ProductGroupBuyingRepository::class);
$id = 'product_group_id';
break;
}
$where = [$id => $data['exsits_id']];
$activity_id = $make->getSearch($where)->column($make->getPk());
if ($activity_id) {
$id = array_unique($activity_id);
$query->where('activity_id', 'in', $id);
} else {
$query->where('activity_id', '<', 0);
}
})
->where('product_type', $data['product_type']);
if ($uid) $query->where('uid', $uid);
});
$query->where('activity_type', $data['product_type'])->where('paid', 1);
switch ($data['product_type']) {
case 1: //秒杀
$query->where(function ($query) {
$query->where(function ($query) {
$query->where('paid', 1);
});
})->when(isset($data['day']), function ($query) use ($data) {
$query->whereDay('StoreOrderOther.create_time', $data['day']);
});
break;
case 2: //预售
if ($data['type'] == 1) { //第一阶段
$query->where('status', 'in', [0, 1, 2, 3, 10]);
} else { //第二阶段
$query->where('status', 'in', [0, 1, 2, 3]);
}
break;
case 3: //助力
break;
case 4:
break;
}
return $query;
}
/**
* TODO 获取退款单数量
* @param $where
* @return mixed
* @author Qinii
* @day 1/4/21
*/
public function getSeckillRefundCount($where, $type = 1)
{
$query = StoreOrderProductOther::getDB()->alias('P')->join('StoreRefundOrder R', 'P.order_id = R.order_id');
$query->join('StoreOrder O', 'StoreOrderOther.order_id = P.order_id');
$query
->when(isset($where['activity_id']), function ($query) use ($where) {
$query->where('P.activity_id', $where['activity_id']);
})
->when(isset($where['product_sku']), function ($query) use ($where) {
$query->where('P.product_sku', $where['product_sku']);
})
->when(isset($where['day']), function ($query) use ($where) {
$query->whereDay('P.create_time', $where['day']);
})
->when($type == 1, function ($query) use ($where) {
$query->where('StoreOrderOther.verify_time', null)->where('StoreOrderOther.delivery_type', null);
}, function ($query) {
$query->where('R.refund_type', 2);
})
->where('P.product_type', 1)->where('R.status', 3);
return $query->count();
}
/**
* TODO 用户的某个商品购买数量
* @param int $uid
* @param int $productId
* @return int
* @author Qinii
* @day 2022/9/26
*/
public function getMaxCountNumber(int $uid, int $productId)
{
return StoreOrderOther::hasWhere('orderProduct', function ($query) use ($productId) {
$query->where('product_id', $productId);
})
->where(function ($query) {
$query->where('is_del', 0)->whereOr(function ($query) {
$query->where('is_del', 1)->where('paid', 1);
});
})->where('StoreOrderOther.uid', $uid)->count();
}
}

View File

@ -0,0 +1,122 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\store\order;
use app\common\model\BaseModel;
use app\common\model\user\User;
use app\common\repositories\store\coupon\StoreCouponRepository;
class StoreGroupOrderOther extends BaseModel
{
const PAY_TYPE_BALANCE = 0; //余额支付
const PAY_TYPE_WECHAT = 1; //微信支付
const PAY_TYPE_ROUTINE = 2; //小程序支付
const PAY_TYPE_H5 = 3; //H5支付
const PAY_TYPE_CREDIT_BUY = 8; //信用购 先货后款
const ON_LINE_PRODUCT = 9; //线上铺货
const ENTITY_PRODUCT = 10; //实体铺货
const ON_CREDIT_PRODUCT = 11; //赊账进货
public static function tablePk(): ?string
{
return 'group_order_id';
}
public static function tableName(): string
{
return 'store_group_order_other';
}
public function orderList()
{
return $this->hasMany(StoreOrderOther::class, 'group_order_id', 'group_order_id');
}
public function user()
{
return $this->hasOne(User::class, 'uid', 'uid');
}
public function getGiveCouponAttr()
{
if (count($this->give_coupon_ids))
return app()->make(StoreCouponRepository::class)->getGiveCoupon($this->give_coupon_ids);
return [];
}
public function getCancelTimeAttr()
{
$timer = ((int)systemConfig('auto_close_order_timer')) ?: 15;
return date('m-d H:i', strtotime("+ $timer minutes", strtotime($this->create_time)));
}
public function getCancelUnixAttr()
{
$timer = ((int)systemConfig('auto_close_order_timer')) ?: 15;
return strtotime("+ $timer minutes", strtotime($this->create_time));
}
public function getGiveCouponIdsAttr($value)
{
return $value ? explode(',', $value) : [];
}
public function setGiveCouponIdsAttr($value)
{
return $value ? implode(',', $value) : '';
}
public function getCombinePayParams($attach = 'order')
{
$params = [
'order_sn' => $this->group_order_sn,
'sub_orders' => [],
'attach' => $attach,
'body' => '订单支付',
];
foreach ($this->orderList as $order) {
if ($order->pay_price > 0) {
$subOrder = [
'pay_price' => $order->pay_price,
'order_sn' => $order->order_sn,
'sub_mchid' => $order->merchant->sub_mchid,
];
$params['sub_orders'][] = $subOrder;
}
}
return $params;
}
public function getPayParams($return_url = '', $attach = 'order')
{
$params = [
'order_sn' => $this->group_order_sn,
'pay_price' => $this->pay_price,
'attach' => $attach,
'body' => '订单支付'
];
if ($return_url) {
$params['return_url'] = $return_url;
}
return $params;
}
public function interest()
{
return $this->hasOne(StoreOrderInterest::class, 'group_order_id', 'group_order_id');
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace app\common\model\store\order;
use app\common\model\BaseModel;
class StoreOrderInterestOther extends BaseModel
{
const STATUS_SETTLED = 1; //已结算
const STATUS_UNSETTLED = 0; //未结算
const STATUS_DELETED = -1; //已删除
public static function tablePk(): ?string
{
return 'id';
}
public static function tableName(): string
{
return 'store_order_interest_other';
}
/**
* 计算利息
* @return string
*/
public function calculateInterest()
{
if ($this->start_time == '0000-00-00 00:00:00') {
return 0;
}
$days = ceil((time() - strtotime($this->start_time)) / 86400);
$days = max($days ,0);
$money = bcmul($this->total_price, ($this->rate / 100), 3);
return bcmul($days, $money, 2);
}
}

View File

@ -0,0 +1,196 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\store\order;
use app\common\model\BaseModel;
use app\common\model\community\Community;
use app\common\model\store\product\ProductGroupUser;
use app\common\model\store\service\StoreService;
use app\common\model\store\shipping\Express;
use app\common\model\system\merchant\Merchant;
use app\common\model\user\User;
use app\common\repositories\store\MerchantTakeRepository;
class StoreOrderOther extends BaseModel
{
const STATUS_WAIT_CONFIRM = 12; //待确认
const STATUS_WAIT_PAY = 0; //待支付
const STATUS_WAIT_COMMENT = 2; //待评价
const STATUS_FINISH = 3; //已完成
public static function tablePk(): ?string
{
return 'order_id';
}
public static function tableName(): string
{
return 'store_order_other';
}
public function orderProduct()
{
return $this->hasMany(StoreOrderProductOther::class, 'order_id', 'order_id');
}
public function refundProduct()
{
return $this->orderProduct()->where('refund_num', '>', 0);
}
public function refundOrder()
{
return $this->hasMany(StoreRefundOrder::class,'order_id','order_id');
}
public function orderStatus()
{
return $this->hasMany(StoreOrderStatusOther::class,'order_id','order_id')->order('change_time DESC');
}
public function merchant()
{
return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
}
public function user()
{
return $this->hasOne(User::class, 'uid', 'uid');
}
public function receipt()
{
return $this->hasOne(StoreOrderReceipt::class, 'order_id', 'order_id');
}
public function spread()
{
return $this->hasOne(User::class, 'uid', 'spread_uid');
}
public function TopSpread()
{
return $this->hasOne(User::class, 'uid', 'top_uid');
}
public function groupOrder()
{
return $this->hasOne(StoreGroupOrderOther::class, 'group_order_id', 'group_order_id');
}
public function verifyService()
{
return $this->hasOne(StoreService::class, 'service_id', 'verify_service_id');
}
public function getTakeAttr()
{
return app()->make(MerchantTakeRepository::class)->get($this->mer_id);
}
public function searchDataAttr($query, $value)
{
return getModelTime($query, $value);
}
public function presellOrder()
{
return $this->hasOne(PresellOrder::class, 'order_id', 'order_id');
}
public function finalOrder()
{
return $this->hasOne(PresellOrder::class,'order_id','order_id');
}
public function groupUser()
{
return $this->hasOne(ProductGroupUser::class,'order_id','order_id');
}
public function profitsharing()
{
return $this->hasMany(StoreOrderProfitsharing::class, 'order_id', 'order_id');
}
public function firstProfitsharing()
{
return $this->hasOne(StoreOrderProfitsharing::class, 'order_id', 'order_id')->where('type', 'order');
}
public function presellProfitsharing()
{
return $this->hasOne(StoreOrderProfitsharing::class, 'order_id', 'order_id')->where('type', 'presell');
}
// 核销订单的自订单列表
public function takeOrderList()
{
return $this->hasMany(self::class,'main_id','order_id')->order('verify_time DESC');
}
public function searchMerIdAttr($query, $value)
{
return $query->where('mer_id', $value);
}
public function getRefundStatusAttr()
{
$day = (int)systemConfig('sys_refund_timer') ?: 15;
return ($this->verify_time ? strtotime($this->verify_time) > strtotime('-' . $day . ' day') : true);
}
public function getOrderExtendAttr($val)
{
return $val ? json_decode($val, true) : null;
}
public function getRefundExtensionOneAttr()
{
if ( $this->refundOrder ){
return $this->refundOrder()->where('status',3)->sum('extension_one');
}
return 0;
}
public function getRefundExtensionTwoAttr()
{
if ( $this->refundOrder ){
return $this->refundOrder()->where('status',3)->sum('extension_two');
}
return 0;
}
public function community()
{
return $this->hasOne(Community::class, 'order_id', 'order_id')->bind(['community_id']);
}
public function getRefundPriceAttr()
{
return StoreRefundOrder::where('order_id',$this->order_id)->where('status',3)->sum('refund_price');
}
public function interest()
{
return $this->hasOne(StoreOrderInterest::class, 'order_id', 'order_id');
}
public function allowCreditPay()
{
return $this->pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && $this->status == self::STATUS_WAIT_PAY;
}
}

View File

@ -0,0 +1,80 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\store\order;
use app\common\model\BaseModel;
use app\common\model\store\product\Product;
use app\common\model\store\product\Spu;
use app\common\model\user\User;
class StoreOrderProductOther extends BaseModel
{
public static function tablePk(): ?string
{
return 'order_product_id';
}
public static function tableName(): string
{
return 'store_order_product_other';
}
public function getCartInfoAttr($value)
{
return json_decode($value, true);
}
public function orderInfo()
{
return $this->hasOne(StoreOrderOther::class, 'order_id', 'order_id');
}
public function user()
{
return $this->hasOne(User::class,'uid','uid');
}
public function product()
{
return $this->hasOne(Product::class,'product_id','product_id');
}
public function spu()
{
return $this->hasOne(Spu::class,'product_id','product_id');
}
public function searchUidAttr($query ,$value)
{
$query->where('uid',$value);
}
public function searchActivitIidAttr($query,$value)
{
$query->where('activity_id',$value);
}
public function searchProductTypeAttr($query,$value)
{
$query->where('product_type',$value);
}
public function searchOrderIdAttr($query,$value)
{
$query->where('order_id',$value);
}
public function searchProductIdAttr($query,$value)
{
$query->where('product_id',$value);
}
}

View File

@ -0,0 +1,47 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\store\order;
use app\common\model\BaseModel;
/**
* Class StoreOrderStatusOther
* @package app\common\model\store\order
* @author xaboy
* @day 2020/6/12
*/
class StoreOrderStatusOther extends BaseModel
{
/**
* @return string|null
* @author xaboy
* @day 2020/6/12
*/
public static function tablePk(): ?string
{
return null;
}
/**
* @return string
* @author xaboy
* @day 2020/6/12
*/
public static function tableName(): string
{
return 'store_order_status_other';
}
}

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,7 @@ use crmeb\basic\BaseController;
use app\common\repositories\store\order\StoreCartRepository;
use app\common\repositories\store\order\StoreGroupOrderRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\order\StoreOtherOrderRepository;
use app\common\repositories\user\UserAddressRepository;
use think\exception\ValidateException;
use crmeb\services\ExpressService;
@ -185,6 +186,24 @@ class StoreOrder extends BaseController
return app('json')->success($this->repository->getList($where, $page, $limit));
}
/**
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author xaboy
* @day 2020/6/10
*/
public function lst_other(StoreOtherOrderRepository $otherOrderRepository)
{
[$page, $limit] = $this->getPage();
$where['status'] = $this->request->param('status');
$where['product_type'] = $this->request->param('product_type', 0);
$where['search'] = $this->request->param('store_name');
$where['uid'] = $this->request->uid();
$where['is_user'] = 1;
return app('json')->success($otherOrderRepository->getList($where, $page, $limit));
}
/**
* @param $id
* @return mixed

View File

@ -62,7 +62,7 @@ Route::group('api/', function () {
Route::group('order', function () {
Route::post('check', '/v2CheckOrder');
Route::post('create', '/v2CreateOrder');
Route::post('other', '/otherOrder');//创建其他订单
Route::post('other', '/otherOrder'); //创建其他订单
})->prefix('api.store.order.StoreOrder');
@ -127,7 +127,10 @@ Route::group('api/', function () {
Route::post('receipt/:id', '/createReceipt');
Route::get('delivery/:id', '/getOrderDelivery');
})->prefix('api.store.order.StoreOrder');
//其他订单
Route::group('other_order', function () {
Route::get('list', '/lst_other');
})->prefix('api.store.order.StoreOrder');
// 预售
Route::group('presell', function () {
Route::post('pay/:id', '/pay');
@ -779,9 +782,6 @@ Route::group('api/', function () {
Route::post('mechant_login', 'Login/mechantLogin');
/**---------------------数据之眼可视化大屏api-------------------- end */
})->prefix('api.dataview.');
})->middleware(AllowOriginMiddleware::class)
->middleware(InstallMiddleware::class)
@ -800,4 +800,3 @@ Route::group('/open-location', function () {
Route::miss('View/h5');
})->middleware(InstallMiddleware::class)
->middleware(CheckSiteOpenMiddleware::class);