|
|
@@ -2,10 +2,14 @@
|
|
|
|
|
|
namespace app\admin\controller\mall;
|
|
|
|
|
|
+use app\admin\logic\ShopOrderLogic;
|
|
|
use app\common\controller\AdminController;
|
|
|
+use app\validate\admin\mall\shopOrder\EditStatus;
|
|
|
+use app\validate\admin\user\user\PhoneSet;
|
|
|
use EasyAdmin\annotation\ControllerAnnotation;
|
|
|
use EasyAdmin\annotation\NodeAnotation;
|
|
|
use think\App;
|
|
|
+use think\exception\ValidateException;
|
|
|
use think\facade\Db;
|
|
|
|
|
|
/**
|
|
|
@@ -16,17 +20,18 @@ class ShopOrder extends AdminController
|
|
|
|
|
|
use \app\admin\traits\Curd;
|
|
|
|
|
|
- public function __construct (App $app)
|
|
|
+ public function __construct(App $app)
|
|
|
{
|
|
|
parent::__construct($app);
|
|
|
|
|
|
$this->model = new \app\common\model\ShopOrder();
|
|
|
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* @NodeAnotation(title="列表")
|
|
|
*/
|
|
|
- public function index ()
|
|
|
+ public function index()
|
|
|
{
|
|
|
if ($this->request->isAjax()) {
|
|
|
// if (input('selectFields')) {
|
|
|
@@ -38,16 +43,16 @@ class ShopOrder extends AdminController
|
|
|
|
|
|
list($page, $limit, $where) = $this->buildTableParames();
|
|
|
|
|
|
- foreach ($where as $key=>$val){
|
|
|
- if ($val[0] == 'status'){
|
|
|
+ foreach ($where as $key => $val) {
|
|
|
+ if ($val[0] == 'status') {
|
|
|
$where[$key][0] = 'o.status';
|
|
|
}
|
|
|
- if ($val[0] == 'created_time'){
|
|
|
+ if ($val[0] == 'created_time') {
|
|
|
$where[$key][0] = 'o.created_time';
|
|
|
$where[$key][2] = sr_getcurtime($where[$key][2]);
|
|
|
}
|
|
|
|
|
|
- if ($val[0] == 'order_type'){
|
|
|
+ if ($val[0] == 'order_type') {
|
|
|
$where[$key][0] = 'o.order_type';
|
|
|
}
|
|
|
|
|
|
@@ -72,30 +77,29 @@ class ShopOrder extends AdminController
|
|
|
->leftJoin('shop_order_shipping s', 's.order_id = o.order_id')
|
|
|
->field('o.*,u.mobile,s.sp_id,s.sp_name,s.sp_mergename,s.sp_mobile')
|
|
|
->order('o.order_id desc')
|
|
|
- ->withAttr('order_sn', function($val, $data){
|
|
|
- return '编号:'.$val;
|
|
|
+ ->withAttr('order_sn', function ($val, $data) {
|
|
|
+ return '编号:' . $val;
|
|
|
})
|
|
|
->page($page, $limit)
|
|
|
->select()->toArray();
|
|
|
|
|
|
|
|
|
-
|
|
|
foreach ($list as $k => $v) {
|
|
|
- $goods_id = $v['goods'][0]['goods_id'];
|
|
|
+ $goods_id = $v['goods'][0]['goods_id'];
|
|
|
$goods_info = Db::name('shop_goods')->where('goods_id', $goods_id)->find();
|
|
|
- if ($goods_info){
|
|
|
+ if ($goods_info) {
|
|
|
$list[$k]['cost_price'] = $goods_info['cost_price'];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$list[$k]['cost_price'] = 0;
|
|
|
}
|
|
|
|
|
|
- if ($v['status'] == 5 || $v['status'] == 6){
|
|
|
+ if ($v['status'] == 5 || $v['status'] == 6) {
|
|
|
// 新的地址
|
|
|
- $ygOrderInfo = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $v['order_sn']))->find();
|
|
|
- $newAddress_info = Db::name('user_address')->where('id', $ygOrderInfo['address_id'])->find();
|
|
|
- $list[$k]['sp_id'] = 99999;
|
|
|
- $list[$k]['sp_mobile'] = $newAddress_info['mobile'];
|
|
|
- $list[$k]['sp_name'] = $newAddress_info['name'];
|
|
|
+ $ygOrderInfo = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $v['order_sn']))->find();
|
|
|
+ $newAddress_info = Db::name('user_address')->where('id', $ygOrderInfo['address_id'])->find();
|
|
|
+ $list[$k]['sp_id'] = 99999;
|
|
|
+ $list[$k]['sp_mobile'] = $newAddress_info['mobile'];
|
|
|
+ $list[$k]['sp_name'] = $newAddress_info['name'];
|
|
|
$list[$k]['sp_mergename'] = $newAddress_info['mergename'];
|
|
|
|
|
|
}
|
|
|
@@ -103,10 +107,10 @@ class ShopOrder extends AdminController
|
|
|
|
|
|
}
|
|
|
$data = [
|
|
|
- 'code' => 0,
|
|
|
- 'msg' => '',
|
|
|
+ 'code' => 0,
|
|
|
+ 'msg' => '',
|
|
|
'count' => $count,
|
|
|
- 'data' => $list,
|
|
|
+ 'data' => $list,
|
|
|
];
|
|
|
return json($data);
|
|
|
}
|
|
|
@@ -116,11 +120,11 @@ class ShopOrder extends AdminController
|
|
|
/**
|
|
|
* @NodeAnotation(title="修改备注")
|
|
|
*/
|
|
|
- public function editdesc ($id)
|
|
|
+ public function editdesc($id)
|
|
|
{
|
|
|
- if ($this->request->isPost()){
|
|
|
+ if ($this->request->isPost()) {
|
|
|
$post = $this->request->post();
|
|
|
- $row = $this->model->where('order_id', $id)->find();
|
|
|
+ $row = $this->model->where('order_id', $id)->find();
|
|
|
empty($row) && $this->error('取消失败');
|
|
|
|
|
|
$row->order_remark = $post['error_text'];
|
|
|
@@ -133,7 +137,7 @@ class ShopOrder extends AdminController
|
|
|
Db::commit();
|
|
|
} catch (\Exception $e) {
|
|
|
Db::rollback();
|
|
|
- $this->error('设置失败'.$e->getMessage());
|
|
|
+ $this->error('设置失败' . $e->getMessage());
|
|
|
}
|
|
|
$this->success('设置成功');
|
|
|
}
|
|
|
@@ -144,52 +148,83 @@ class ShopOrder extends AdminController
|
|
|
return $this->fetch();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @NodeAnotation(title="修改订单状态")
|
|
|
+ */
|
|
|
+ public function editstatus($id)
|
|
|
+ {
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $post = $this->request->post();
|
|
|
+
|
|
|
+ try {
|
|
|
+ validate(EditStatus::class)->check($post);
|
|
|
+ } catch (ValidateException $e) {
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = ShopOrderLogic::editStatus($post['id'], $post['status']);
|
|
|
+ if ($result !== true) {
|
|
|
+ $this->error($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('修改订单状态成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ $row = $this->model->where('order_id', $id)->find();
|
|
|
+ $row['status_map'] = ShopOrderLogic::getStatusMap();
|
|
|
+ $this->assign('info', $row);
|
|
|
+
|
|
|
+ return $this->fetch('editstatus');
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @NodeAnotation(title="列表")
|
|
|
*/
|
|
|
- public function details ($orderId)
|
|
|
+ public function details($orderId)
|
|
|
{
|
|
|
$order = $this->model->where(['order_id' => $orderId])->with(['user', 'goods', 'shipping'])->find()->toArray();
|
|
|
|
|
|
- if ($order['status'] == 5 || $order['status'] == 6){
|
|
|
+ if ($order['status'] == 5 || $order['status'] == 6) {
|
|
|
// 新的地址
|
|
|
- $ygOrderInfo = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $order['order_sn']))->find();
|
|
|
- $newAddress_info = Db::name('user_address')->where('id', $ygOrderInfo['address_id'])->find();
|
|
|
- $order['shipping']['sp_id'] = 99999;
|
|
|
- $order['shipping']['sp_mobile'] = $newAddress_info['mobile'];
|
|
|
- $order['shipping']['sp_name'] = $newAddress_info['name'];
|
|
|
+ $ygOrderInfo = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $order['order_sn']))->find();
|
|
|
+ $newAddress_info = Db::name('user_address')->where('id', $ygOrderInfo['address_id'])->find();
|
|
|
+ $order['shipping']['sp_id'] = 99999;
|
|
|
+ $order['shipping']['sp_mobile'] = $newAddress_info['mobile'];
|
|
|
+ $order['shipping']['sp_name'] = $newAddress_info['name'];
|
|
|
$order['shipping']['sp_mergename'] = $newAddress_info['mergename'];
|
|
|
}
|
|
|
$this->assign('data', $order);
|
|
|
return $this->fetch();
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* @NodeAnotation(title="列表")
|
|
|
*/
|
|
|
- public function delivery ($orderId)
|
|
|
+ public function delivery($orderId)
|
|
|
{
|
|
|
- $express = Db::name('express')->field('id,name,code')->select()->toArray();
|
|
|
+ $express = Db::name('express')->field('id,name,code')->select()->toArray();
|
|
|
$shipping = Db::name('shop_order_shipping')->where(['order_id' => $orderId])->findOrEmpty();
|
|
|
- $order = Db::name('shop_order')->where('order_id', $shipping['order_id'])->find();
|
|
|
+ $order = Db::name('shop_order')->where('order_id', $shipping['order_id'])->find();
|
|
|
$this->assign('express', $express);
|
|
|
- if ($order['status'] == 5 || $order['status'] == 6){
|
|
|
+ if ($order['status'] == 5 || $order['status'] == 6) {
|
|
|
// 新的地址
|
|
|
- $ygOrderInfo = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $order['order_sn']))->find();
|
|
|
- $newAddress_info = Db::name('user_address')->where('id', $ygOrderInfo['address_id'])->find();
|
|
|
- $shipping['sp_id'] = 99999;
|
|
|
- $shipping['sp_mobile'] = $newAddress_info['mobile'];
|
|
|
- $shipping['sp_name'] = $newAddress_info['name'];
|
|
|
+ $ygOrderInfo = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $order['order_sn']))->find();
|
|
|
+ $newAddress_info = Db::name('user_address')->where('id', $ygOrderInfo['address_id'])->find();
|
|
|
+ $shipping['sp_id'] = 99999;
|
|
|
+ $shipping['sp_mobile'] = $newAddress_info['mobile'];
|
|
|
+ $shipping['sp_name'] = $newAddress_info['name'];
|
|
|
$shipping['sp_mergename'] = $newAddress_info['mergename'];
|
|
|
}
|
|
|
$this->assign('shipping', $shipping);
|
|
|
|
|
|
return $this->fetch();
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* @NodeAnotation(title="列表")
|
|
|
*/
|
|
|
- public function deliverySave ()
|
|
|
+ public function deliverySave()
|
|
|
{
|
|
|
if ($this->request->isPost()) {
|
|
|
$data = $this->request->post();
|
|
|
@@ -203,18 +238,18 @@ class ShopOrder extends AdminController
|
|
|
// 发货
|
|
|
if ($order_info = Db::name('shop_order')->where(['order_id' => $data['order_id']])->where('status', 'in', [5])->find()) {
|
|
|
|
|
|
- $res = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 6]);
|
|
|
+ $res = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 6]);
|
|
|
$yg_orderinfo = Db::name('yg_order')->where('order_sn', $order_info['order_sn'])->find();
|
|
|
Db::name('yg_buy_record')->where('yg_id', $yg_orderinfo['id'])->where('status', 3)->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 4]);
|
|
|
|
|
|
// 重新发货
|
|
|
- }elseif($order_info = Db::name('shop_order')->where(['order_id' => $data['order_id']])->where('status', 'in', [6])->find()){
|
|
|
- $res = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 6]);
|
|
|
+ } elseif ($order_info = Db::name('shop_order')->where(['order_id' => $data['order_id']])->where('status', 'in', [6])->find()) {
|
|
|
+ $res = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 6]);
|
|
|
$yg_orderinfo = Db::name('yg_order')->where('order_sn', $order_info['order_sn'])->find();
|
|
|
Db::name('yg_buy_record')->where('yg_id', $yg_orderinfo['id'])->where('status', 4)->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number']]);
|
|
|
|
|
|
- }else{
|
|
|
- $res = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'],'status' => 2]);
|
|
|
+ } else {
|
|
|
+ $res = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 2]);
|
|
|
}
|
|
|
|
|
|
|