chengkun
2025-06-05 4080b5997b38ca84b3b203c7101dcadb97b76925
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
 
namespace app\admin\controller;
 
use think\Exception;
use think\facade\Db;
use think\facade\View;
use think\facade\Request;
use app\supplier\validate\LogisticsProduct;
 
class ThirdPartyLogisticsProductTemp extends Common {
    
    /**
     * 新建物流产品首页
     * @return string
     */
    public function index() {
        ////////
        return View::fetch();
    }
    
    /**
     * 审核物流产品
     * @return array|int[]
     */
    public function reviewLogisticsProduct() {
        // 开始数据库事务
        Db::startTrans();
        try {
            if (!Request::isPost()) {
                throw new Exception(lang('request_method_incorrect'));
            }
            $id = input('post.id');
            if (is_numeric($id)) {
                $status = input('post.status');
                //更新数据
                $info = Db::name('logistics_product')->field('id,status')->where('id', $id)->find();
                if (!$info) {
                    return $this->errorResponse(lang('request_method_incorrect'));
                }
                if ($status == 1) {
                    Db::name('logistics_product')->where('id', $id)->update(['status' => 1]);
                    $message = '操作成功,审核通过';
                } else {
                    Db::name('logistics_product')->where('id', $id)->update(['status' => 2]);
                    $message = '操作成功,审核不通过';
                }
                // 提交事务
                Db::commit();
                return $this->successResponse($message);
            } else {
                return $this->errorResponse(lang('request_method_incorrect'));
            }
        } catch (Exception $exc) {
            // 回滚事务
            Db::rollback();
            return $this->errorResponse($exc->getMessage());
        }
    }
    
    
    /**
     * 获取物流产品列表
     */
    public function logisticsProductList() {
        if (Request::isPost()) {
            $kw = input('kw');
            if (!empty($kw)) {
                $condition[] = array('product_name_cn|product_name_en|docking_code', 'like', "%$kw%");
            }
            $condition[] = ['status', '=', 3];
            $p = input('p', 1);
            $_GET['p'] = $p;
            $other['page_size'] = input('page_size', 20);
            $order = 'status asc,edit_time asc';
            $count = Db::name('logistics_product')->where($condition)->count();
            $list = Db::name('logistics_product')->field("id,platform_logistics_product_id,logistics_type,docking_system,docking_code,product_name_cn,product_name_en,value_added_services,status,edit_time")->where($condition)
                ->withAttr('edit_time', function ($value) {
                    return date('Y-m-d H:i:s', $value);
                })->withAttr('platform_logistics_product_name', function ($value, $data) {
                    return $data['platform_logistics_product_id'] ? Db::name('platform_logistics_product')->where('id', $data['platform_logistics_product_id'])->field('product_name_cn,product_name_en,cycle_start,cycle_end')->find() : '';
                })
                ->order($order)->page($p, $other['page_size'])->select()->toArray();
            $other['count'] = $count;
            
            $result['other'] = $other;
            if (!$list) {
                $list = [];
                $result['code'] = 400;
                return $result;
            } else {
                foreach ($list as &$item) {
                    if ($item['value_added_services']) {
                        $item['value_added_services'] = json_decode($item['value_added_services'], TRUE);
                    } else {
                        $item['value_added_services'] = [];
                    }
                }
                $result['code'] = 200;
                $result['list'] = $list;
                return $result;
            }
            return $result;
        }
    }
    
    /**
     * 获取增值服务列表
     */
    public function logisticsVasList() {
        if (Request::isPost()) {
            $order = 'order_id asc,id asc';
            $list = Db::name('logistics_vas')->field("id,vas_name,vas_code")->order($order)->cacheAlways(TRUE, 0, 'logistics_vas')->select()->toArray();
            if (!$list) {
                $list = [];
            }
            $d['code'] = 200;
            $d['list'] = $list;
            return $d;
        }
    }
    
}