mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
修改商城模块
This commit is contained in:
parent
d50010f87f
commit
478745eb4a
@ -69,20 +69,7 @@ class ShopOrder extends Controller
|
||||
*/
|
||||
protected function _index_page_filter(array &$data)
|
||||
{
|
||||
$mids = array_unique(array_merge(array_column($data, 'mid'), array_column($data, 'from')));
|
||||
$mems = $this->app->db->name('DataMember')->whereIn('id', $mids)->column('*', 'id');
|
||||
$query = $this->app->db->name('ShopOrderItem')->where(['status' => 1, 'deleted' => 0]);
|
||||
$items = $query->whereIn('order_no', array_unique(array_column($data, 'order_no')))->select()->toArray();
|
||||
foreach ($data as &$vo) {
|
||||
$vo['items'] = [];
|
||||
$vo['member'] = $mems[$vo['mid']] ?? [];
|
||||
$vo['fromer'] = $mems[$vo['from']] ?? [];
|
||||
foreach ($items as $item) {
|
||||
if ($vo['order_no'] === $item['order_no']) {
|
||||
$vo['items'][] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
OrderService::instance()->buildItemData($data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,7 +120,8 @@ class ShopOrder extends Controller
|
||||
{
|
||||
try {
|
||||
$data = $this->_vali([
|
||||
'code.require' => '快递编号不能为空!', 'number.require' => '配送单号不能为空!',
|
||||
'code.require' => '快递编号不能为空!',
|
||||
'number.require' => '配送单号不能为空!',
|
||||
]);
|
||||
$this->result = OrderService::instance()->trackExpress($data['code'], $data['number']);
|
||||
if (empty($this->result['code'])) $this->error($this->result['info']);
|
||||
@ -154,7 +142,10 @@ class ShopOrder extends Controller
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
$map = $this->_vali(['order_no.require' => '订单编号不能为空!']);
|
||||
$map = $this->_vali([
|
||||
'deleted.value' => 0,
|
||||
'order_no.require' => '订单编号不能为空!',
|
||||
]);
|
||||
$order = $this->app->db->name($this->table)->where($map)->find();
|
||||
if (empty($order)) $this->error('订单查询异常');
|
||||
if (!in_array($order['status'], [1, 2])) $this->error('订单不能取消!');
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\data\controller;
|
||||
|
||||
use app\data\service\OrderService;
|
||||
use think\admin\Controller;
|
||||
|
||||
/**
|
||||
@ -67,20 +68,7 @@ class ShopOrderSend extends Controller
|
||||
*/
|
||||
protected function _index_page_filter(array &$data)
|
||||
{
|
||||
$mids = array_unique(array_merge(array_column($data, 'mid'), array_column($data, 'from')));
|
||||
$mems = $this->app->db->name('DataMember')->whereIn('id', $mids)->column('*', 'id');
|
||||
$query = $this->app->db->name('ShopOrderItem')->where(['status' => 1, 'deleted' => 0]);
|
||||
$items = $query->whereIn('order_no', array_unique(array_column($data, 'order_no')))->select()->toArray();
|
||||
foreach ($data as &$vo) {
|
||||
$vo['items'] = [];
|
||||
$vo['member'] = $mems[$vo['mid']] ?? [];
|
||||
$vo['fromer'] = $mems[$vo['from']] ?? [];
|
||||
foreach ($items as $item) {
|
||||
if ($vo['order_no'] === $item['order_no']) {
|
||||
$vo['items'][] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
OrderService::instance()->buildItemData($data);
|
||||
}
|
||||
|
||||
}
|
@ -42,17 +42,7 @@ class Order extends Auth
|
||||
$query = $this->_query('ShopOrder')->equal('status,order_no');
|
||||
$result = $query->where($map)->order('id desc')->page(true, false, false, 20);
|
||||
if (count($result['list']) > 0) {
|
||||
$codes = array_unique(array_column($result['list'], 'order_no'));
|
||||
$items = $this->app->db->name('ShopOrderItem')->whereIn('order_no', $codes)->select()->toArray();
|
||||
foreach ($result['list'] as &$vo) {
|
||||
[$vo['count'], $vo['items']] = [0, []];
|
||||
foreach ($items as $item) {
|
||||
if ($vo['order_no'] === $item['order_no']) {
|
||||
$vo['items'][] = $item;
|
||||
$vo['count'] += $item['stock_sales'];
|
||||
}
|
||||
}
|
||||
}
|
||||
OrderService::instance()->buildItemData($result['list']);
|
||||
}
|
||||
$this->success('获取订单数据成功!', $result);
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace app\data\service;
|
||||
|
||||
use think\admin\extend\CodeExtend;
|
||||
use think\admin\Service;
|
||||
use think\admin\service\InterfaceService;
|
||||
|
||||
@ -65,4 +64,34 @@ class OrderService extends Service
|
||||
'type' => 'free', 'express' => $code, 'number' => $number,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定订单详情数据
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function buildItemData(array &$data = []): array
|
||||
{
|
||||
$mids = array_unique(array_merge(array_column($data, 'mid'), array_column($data, 'from')));
|
||||
$members = $this->app->db->name('DataMember')->whereIn('id', $mids)->column('*', 'id');
|
||||
// 商品详情管理
|
||||
$query = $this->app->db->name('ShopOrderItem')->where(['status' => 1, 'deleted' => 0]);
|
||||
$items = $query->whereIn('order_no', array_unique(array_column($data, 'order_no')))->select()->toArray();
|
||||
foreach ($data as &$vo) {
|
||||
[$vo['count'], $vo['items']] = [0, []];
|
||||
$vo['member'] = $members[$vo['mid']] ?? [];
|
||||
$vo['fromer'] = $members[$vo['from']] ?? [];
|
||||
foreach ($items as $item) {
|
||||
if ($vo['order_no'] === $item['order_no']) {
|
||||
$vo['count'] += $item['stock_sales'];
|
||||
$vo['items'][] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user