|
@@ -1,7 +1,9 @@
|
|
|
<?php
|
|
|
|
|
|
namespace app\admin\controller\shopro\order;
|
|
|
+use addons\shopro\model\User;
|
|
|
use app\admin\controller\shopro\Base;
|
|
|
+use think\Db;
|
|
|
/**
|
|
|
* 交易订单管理
|
|
|
*
|
|
@@ -89,46 +91,41 @@ class OrderShift extends Base
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- // 构建查询条件
|
|
|
- private function buildSearchOrder()
|
|
|
+ public function audit($ids)
|
|
|
{
|
|
|
- $filter = $this->request->get("filter", '');
|
|
|
- $filter = (array)json_decode($filter, true);
|
|
|
- $filter = $filter ? $filter : [];
|
|
|
-
|
|
|
- $status = isset($filter['status']) ? $filter['status'] : 'all';
|
|
|
- $nickname = isset($filter['nickname']) ? $filter['nickname'] : '';
|
|
|
- $mobile = isset($filter['user_phone']) ? $filter['user_phone'] : '';
|
|
|
-
|
|
|
- $name = $this->model->getQuery()->getTable();
|
|
|
- $tableName = $name . '.';
|
|
|
-
|
|
|
- $orders = $this->model->withTrashed();
|
|
|
-
|
|
|
- if ($nickname || $mobile) {
|
|
|
- $orders = $orders->whereExists(function ($query) use ($nickname, $mobile, $tableName) {
|
|
|
- $userTableName = (new \app\admin\model\User())->getQuery()->getTable();
|
|
|
-
|
|
|
- $query = $query->table($userTableName)->where($userTableName . '.id=' . $tableName . 'user_id');
|
|
|
+ $ids = explode(',', $ids);
|
|
|
+ $successCount = 0;
|
|
|
+ $failedCount = 0;
|
|
|
+ $applyList = $this->model->where('id', 'in', $ids)->select();
|
|
|
+ if (!$applyList) $this->error('未找到申请记录');
|
|
|
+ $operate = $this->request->post('operate');
|
|
|
+ $integral = intval($this->request->post('integral')) ;
|
|
|
+ foreach ($applyList as $apply) {
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ if($operate == 1 && $integral> 0)User::score($integral, $apply->user_id, 'order_shift',$apply->id);
|
|
|
+ $apply->sh_status = $operate;
|
|
|
+ $apply->remark = $this->request->post('remark');
|
|
|
+ $apply->sh_time = date("Y-m-d H:i:s");
|
|
|
+ if($integral> 0 && $operate == 1) $apply->integral = $integral;
|
|
|
+ $apply->save();
|
|
|
+ Db::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $failedCount++;
|
|
|
+ $lastErrorMessage = $e->getMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (count($ids) === 1) {
|
|
|
+ if ($successCount) $this->success('操作成功');
|
|
|
+ if ($failedCount) $this->error($lastErrorMessage);
|
|
|
+ } else {
|
|
|
+ $this->success('成功: ' . $successCount . '笔' . ' | 失败: ' . $failedCount . '笔');
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if ($nickname) {
|
|
|
- $query = $query->where('nickname', 'like', "%{$nickname}%");
|
|
|
- }
|
|
|
|
|
|
- if ($mobile) {
|
|
|
- $query = $query->where('mobile', 'like', "%{$mobile}%");
|
|
|
- }
|
|
|
|
|
|
- return $query;
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
- // 订单状态
|
|
|
- if ($status != 'all' && in_array($status, ['invalid', 'cancel', 'nopay', 'payed', 'finish'])) {
|
|
|
- $orders = $orders->{$status}();
|
|
|
- }
|
|
|
|
|
|
- return $orders;
|
|
|
- }
|
|
|
}
|