Order.php 19.3 KB
Newer Older
D
devil 已提交
1 2 3 4
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
D
2.0  
Devil 已提交
5
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
D
devil 已提交
6
// +----------------------------------------------------------------------
D
2.0  
Devil 已提交
7
// | Licensed ( https://opensource.org/licenses/mit-license.php )
D
devil 已提交
8 9 10 11 12
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\index\form;

D
Devil 已提交
13
use think\facade\Db;
D
devil 已提交
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
use app\service\PaymentService;
use app\service\ExpressService;

/**
 * 订单动态表格
 * @author  Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2020-06-08
 * @desc    description
 */
class Order
{
    // 基础条件
    public $condition_base = [
        ['is_delete_time', '=', 0],
        ['user_is_delete_time', '=', 0],
    ];

    /**
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-06-29
     * @desc    description
     * @param   [array]           $params [输入参数]
     */
    public function __construct($params = [])
    {
        // 用户信息
        if(!empty($params['system_user']))
        {
            $this->condition_base[] = ['user_id', '=', $params['system_user']['id']];
        }
    }

    /**
     * 入口
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-06-08
     * @desc    description
     * @param   [array]           $params [输入参数]
     */
    public function Run($params = [])
    {
D
devil 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
        // 基础配置
        $base = [
            'key_field'     => 'id',
            'is_search'     => 1,
            'search_url'    => MyUrl('index/order/index'),
            'detail_title'  => '基础信息',
            'is_middle'     => 0,
        ];

        // 表单配置
        $form = [
            [
                'label'         => '基础信息',
                'view_type'     => 'module',
                'view_key'      => 'order/module/goods',
                'grid_size'     => 'xl',
                'search_config' => [
                    'form_type'             => 'input',
                    'form_name'             => 'id',
                    'where_type'            => 'like',
                    'where_type_custom'     => 'in',
                    'where_value_custom'    => 'WhereBaseGoodsInfo',
                    'placeholder'           => '请输入订单号/商品名称/型号',
D
devil 已提交
84
                ],
D
devil 已提交
85 86 87 88 89 90
            ],
            [
                'label'         => '订单状态',
                'view_type'     => 'field',
                'view_key'      => 'status',
                'view_data_key' => 'name',
D
Devil 已提交
91
                'view_data'     => MyConst('common_order_user_status'),
92
                'is_sort'       => 1,
D
devil 已提交
93 94 95
                'search_config' => [
                    'form_type'         => 'select',
                    'where_type'        => 'in',
D
Devil 已提交
96
                    'data'              => MyConst('common_order_user_status'),
D
devil 已提交
97 98 99
                    'data_key'          => 'id',
                    'data_name'         => 'name',
                    'is_multiple'       => 1,
D
devil 已提交
100
                ],
D
devil 已提交
101 102 103 104 105
            ],
            [
                'label'         => '支付状态',
                'view_type'     => 'module',
                'view_key'      => 'order/module/pay_status',
106
                'is_sort'       => 1,
D
devil 已提交
107 108 109 110
                'search_config' => [
                    'form_type'         => 'select',
                    'form_name'         => 'pay_status',
                    'where_type'        => 'in',
D
Devil 已提交
111
                    'data'              => MyConst('common_order_pay_status'),
D
devil 已提交
112 113 114
                    'data_key'          => 'id',
                    'data_name'         => 'name',
                    'is_multiple'       => 1,
D
devil 已提交
115
                ],
D
devil 已提交
116 117 118 119 120
            ],
            [
                'label'         => '总价(元)',
                'view_type'     => 'field',
                'view_key'      => 'total_price',
121
                'is_sort'       => 1,
D
devil 已提交
122 123 124
                'search_config' => [
                    'form_type'         => 'section',
                    'is_point'          => 1,
D
devil 已提交
125
                ],
D
devil 已提交
126 127 128 129 130
            ],
            [
                'label'         => '支付金额(元)',
                'view_type'     => 'field',
                'view_key'      => 'pay_price',
131
                'is_sort'       => 1,
D
devil 已提交
132 133 134
                'search_config' => [
                    'form_type'         => 'section',
                    'is_point'          => 1,
D
devil 已提交
135
                ],
D
devil 已提交
136 137 138 139 140
            ],
            [
                'label'         => '单价(元)',
                'view_type'     => 'field',
                'view_key'      => 'price',
141
                'is_sort'       => 1,
D
devil 已提交
142 143 144
                'search_config' => [
                    'form_type'         => 'section',
                    'is_point'          => 1,
D
devil 已提交
145
                ],
D
devil 已提交
146 147 148 149 150 151
            ],
            [
                'label'         => '订单模式',
                'view_type'     => 'field',
                'view_key'      => 'order_model',
                'view_data_key' => 'name',
D
Devil 已提交
152
                'view_data'     => MyConst('common_site_type_list'),
153
                'is_sort'       => 1,
D
devil 已提交
154 155 156
                'search_config' => [
                    'form_type'         => 'select',
                    'where_type'        => 'in',
D
Devil 已提交
157
                    'data'              => MyConst('common_site_type_list'),
D
devil 已提交
158 159 160
                    'data_key'          => 'value',
                    'data_name'         => 'name',
                    'is_multiple'       => 1,
D
devil 已提交
161
                ],
D
devil 已提交
162 163 164 165 166 167
            ],
            [
                'label'         => '下单平台',
                'view_type'     => 'field',
                'view_key'      => 'client_type',
                'view_data_key' => 'name',
D
Devil 已提交
168
                'view_data'     => MyConst('common_platform_type'),
169
                'is_sort'       => 1,
D
devil 已提交
170 171 172
                'search_config' => [
                    'form_type'         => 'select',
                    'where_type'        => 'in',
D
Devil 已提交
173
                    'data'              => MyConst('common_platform_type'),
D
devil 已提交
174 175 176
                    'data_key'          => 'value',
                    'data_name'         => 'name',
                    'is_multiple'       => 1,
D
devil 已提交
177
                ],
D
devil 已提交
178 179 180 181 182 183 184 185 186 187 188 189
            ],
            [
                'label'         => '地址信息',
                'view_type'     => 'module',
                'view_key'      => 'order/module/address',
                'grid_size'     => 'sm',
                'search_config' => [
                    'form_type'             => 'input',
                    'form_name'             => 'id',
                    'where_type'            => 'like',
                    'where_type_custom'     => 'in',
                    'where_value_custom'    => 'WhereValueAddressInfo',
D
devil 已提交
190
                ],
D
devil 已提交
191 192 193 194 195 196 197 198 199 200 201 202
            ],
            [
                'label'         => '取货信息',
                'view_type'     => 'module',
                'view_key'      => 'order/module/take',
                'width'         => 125,
                'search_config' => [
                    'form_type'             => 'input',
                    'form_name'             => 'id',
                    'where_type'            => 'like',
                    'where_type_custom'     => 'in',
                    'where_value_custom'    => 'WhereValueTakeInfo',
D
devil 已提交
203
                ],
D
devil 已提交
204 205 206 207 208
            ],
            [
                'label'         => '退款金额(元)',
                'view_type'     => 'field',
                'view_key'      => 'refund_price',
209
                'is_sort'       => 1,
D
devil 已提交
210 211 212
                'search_config' => [
                    'form_type'         => 'section',
                    'is_point'          => 1,
D
devil 已提交
213
                ],
D
devil 已提交
214 215 216 217 218
            ],
            [
                'label'         => '退货数量',
                'view_type'     => 'field',
                'view_key'      => 'returned_quantity',
219
                'is_sort'       => 1,
D
devil 已提交
220 221
                'search_config' => [
                    'form_type'         => 'section',
D
devil 已提交
222
                ],
D
devil 已提交
223 224 225 226 227
            ],
            [
                'label'         => '购买总数',
                'view_type'     => 'field',
                'view_key'      => 'buy_number_count',
228
                'is_sort'       => 1,
D
devil 已提交
229 230
                'search_config' => [
                    'form_type'         => 'section',
D
devil 已提交
231
                ],
D
devil 已提交
232 233 234 235 236
            ],
            [
                'label'         => '增加金额(元)',
                'view_type'     => 'field',
                'view_key'      => 'increase_price',
237
                'is_sort'       => 1,
D
devil 已提交
238 239 240
                'search_config' => [
                    'form_type'         => 'section',
                    'is_point'          => 1,
D
devil 已提交
241
                ],
D
devil 已提交
242 243 244 245 246
            ],
            [
                'label'         => '优惠金额(元)',
                'view_type'     => 'field',
                'view_key'      => 'preferential_price',
247
                'is_sort'       => 1,
D
devil 已提交
248 249 250
                'search_config' => [
                    'form_type'         => 'section',
                    'is_point'          => 1,
D
devil 已提交
251
                ],
D
devil 已提交
252 253 254 255 256
            ],
            [
                'label'         => '支付方式',
                'view_type'     => 'field',
                'view_key'      => 'payment_name',
257
                'is_sort'       => 1,
D
devil 已提交
258 259 260 261 262 263 264 265
                'search_config' => [
                    'form_type'         => 'select',
                    'form_name'         => 'payment_id',
                    'where_type'        => 'in',
                    'data'              => PaymentService::PaymentList(),
                    'data_key'          => 'id',
                    'data_name'         => 'name',
                    'is_multiple'       => 1,
D
devil 已提交
266
                ],
D
devil 已提交
267 268 269 270 271
            ],
            [
                'label'         => '留言信息',
                'view_type'     => 'field',
                'view_key'      => 'user_note',
272
                'is_sort'       => 1,
D
devil 已提交
273 274 275
                'search_config' => [
                    'form_type'         => 'select',
                    'where_type'        => 'like',
D
devil 已提交
276
                ],
D
devil 已提交
277 278 279 280 281 282 283 284 285 286
            ],
            [
                'label'         => '扩展信息',
                'view_type'     => 'module',
                'view_key'      => 'order/module/extension',
                'grid_size'     => 'sm',
                'search_config' => [
                    'form_type'         => 'input',
                    'form_name'         => 'extension_data',
                    'where_type'        => 'like',
D
devil 已提交
287
                ],
D
devil 已提交
288 289 290 291 292
            ],
            [
                'label'         => '快递公司',
                'view_type'     => 'field',
                'view_key'      => 'express_name',
293
                'is_sort'       => 1,
D
devil 已提交
294 295 296 297 298 299 300 301
                'search_config' => [
                    'form_type'         => 'select',
                    'form_name'         => 'express_id',
                    'data'              => ExpressService::ExpressList(),
                    'where_type'        => 'in',
                    'data_key'          => 'id',
                    'data_name'         => 'name',
                    'is_multiple'       => 1,
D
devil 已提交
302
                ],
D
devil 已提交
303 304 305 306 307
            ],
            [
                'label'         => '快递单号',
                'view_type'     => 'field',
                'view_key'      => 'express_number',
308
                'is_sort'       => 1,
D
devil 已提交
309 310 311
                'search_config' => [
                    'form_type'         => 'input',
                    'where_type'        => 'like',
D
devil 已提交
312
                ],
D
devil 已提交
313 314 315 316 317
            ],
            [
                'label'         => '是否评论',
                'view_type'     => 'module',
                'view_key'      => 'order/module/is_comments',
318
                'is_sort'       => 1,
D
devil 已提交
319 320 321 322
                'search_config' => [
                    'form_type'             => 'select',
                    'where_type'            => 'in',
                    'form_name'             => 'user_is_comments',
D
Devil 已提交
323
                    'data'                  => MyConst('common_is_text_list'),
D
devil 已提交
324 325 326 327 328
                    'data_key'              => 'id',
                    'data_name'             => 'name',
                    'where_type_custom'     => 'WhereTypyUserIsComments',
                    'where_value_custom'    => 'WhereValueUserIsComments',
                    'is_multiple'           => 1,
D
devil 已提交
329
                ],
D
devil 已提交
330 331 332 333 334
            ],
            [
                'label'         => '确认时间',
                'view_type'     => 'field',
                'view_key'      => 'confirm_time',
335
                'is_sort'       => 1,
D
devil 已提交
336 337
                'search_config' => [
                    'form_type'         => 'datetime',
D
devil 已提交
338
                ],
D
devil 已提交
339 340 341 342 343
            ],
            [
                'label'         => '支付时间',
                'view_type'     => 'field',
                'view_key'      => 'pay_time',
344
                'is_sort'       => 1,
D
devil 已提交
345 346
                'search_config' => [
                    'form_type'         => 'datetime',
D
devil 已提交
347
                ],
D
devil 已提交
348 349 350 351 352
            ],
            [
                'label'         => '发货时间',
                'view_type'     => 'field',
                'view_key'      => 'delivery_time',
353
                'is_sort'       => 1,
D
devil 已提交
354 355
                'search_config' => [
                    'form_type'         => 'datetime',
D
devil 已提交
356
                ],
D
devil 已提交
357 358 359 360 361
            ],
            [
                'label'         => '完成时间',
                'view_type'     => 'field',
                'view_key'      => 'collect_time',
362
                'is_sort'       => 1,
D
devil 已提交
363 364
                'search_config' => [
                    'form_type'         => 'datetime',
D
devil 已提交
365
                ],
D
devil 已提交
366 367 368 369 370
            ],
            [
                'label'         => '取消时间',
                'view_type'     => 'field',
                'view_key'      => 'cancel_time',
371
                'is_sort'       => 1,
D
devil 已提交
372 373
                'search_config' => [
                    'form_type'         => 'datetime',
D
devil 已提交
374
                ],
D
devil 已提交
375 376 377 378 379
            ],
            [
                'label'         => '关闭时间',
                'view_type'     => 'field',
                'view_key'      => 'close_time',
380
                'is_sort'       => 1,
D
devil 已提交
381 382
                'search_config' => [
                    'form_type'         => 'datetime',
D
devil 已提交
383
                ],
D
devil 已提交
384 385 386 387 388
            ],
            [
                'label'         => '创建时间',
                'view_type'     => 'field',
                'view_key'      => 'add_time',
389
                'is_sort'       => 1,
D
devil 已提交
390 391
                'search_config' => [
                    'form_type'         => 'datetime',
D
devil 已提交
392
                ],
D
devil 已提交
393 394 395 396 397
            ],
            [
                'label'         => '更新时间',
                'view_type'     => 'field',
                'view_key'      => 'upd_time',
398
                'is_sort'       => 1,
D
devil 已提交
399 400
                'search_config' => [
                    'form_type'         => 'datetime',
D
devil 已提交
401 402
                ],
            ],
D
devil 已提交
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
            [
                'label'         => '操作',
                'view_type'     => 'operate',
                'view_key'      => 'order/module/operate',
                'align'         => 'center',
                'fixed'         => 'right',
            ],
        ];

        // 是否启用订单批量支付
        if(MyC('home_is_enable_order_bulk_pay') == 1)
        {
            array_unshift($form, [
                'view_type'         => 'checkbox',
                'is_checked'        => 0,
                'checked_text'      => '反选',
                'not_checked_text'  => '全选',
                'not_show_key'      => 'status',
                'not_show_data'     => [0,2,3,4,5,6],
                'align'             => 'center',
                'width'             => 80,
                'view_key'          => 'order_form_checkbox_value',
            ]);
        }

        return [
            'base'  => $base,
            'form'  => $form,
D
devil 已提交
431 432 433 434
        ];
    }

    /**
D
devil 已提交
435
     * 评论条件符号处理
D
devil 已提交
436 437 438 439 440
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-06-08
     * @desc    description
D
devil 已提交
441 442 443
     * @param   [string]          $form_key     [表单数据key]
     * @param   [array]           $params       [输入参数]
     */
D
devil 已提交
444
    public function WhereTypyUserIsComments($form_key, $params = [])
D
devil 已提交
445 446 447
    {
        if(isset($params[$form_key]))
        {
D
devil 已提交
448 449 450 451 452 453 454
            // 条件值是 0,1
            // 解析成数组,都存在则返回null,则1 >, 0 =
            $value = explode(',', urldecode($params[$form_key]));
            if(count($value) == 1)
            {
                return in_array(1, $value) ? '>' : '=';
            }
D
devil 已提交
455 456 457 458 459
        }
        return null;
    }

    /**
D
devil 已提交
460
     * 评论条件值处理
D
devil 已提交
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-06-08
     * @desc    description
     * @param   [string]          $form_key     [表单数据key]
     * @param   [array]           $params       [输入参数]
     */
    public function WhereValueUserIsComments($value, $params = [])
    {
        return (count($value) == 2) ? null : 0;
    }

    /**
     * 取货码条件处理
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-06-08
     * @desc    description
D
devil 已提交
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
     * @param   [string]          $value    [条件值]
     * @param   [array]           $params   [输入参数]
     */
    public function WhereValueTakeInfo($value, $params = [])
    {
        if(!empty($value))
        {
            // 获取订单 id
            $ids = Db::name('OrderExtractionCode')->where('code', '=', $value)->column('order_id');

            // 避免空条件造成无效的错觉
            return empty($ids) ? [0] : $ids;
        }
        return $value;
    }

    /**
     * 收件地址条件处理
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-06-08
     * @desc    description
     * @param   [string]          $value    [条件值]
     * @param   [array]           $params   [输入参数]
     */
    public function WhereValueAddressInfo($value, $params = [])
    {
        if(!empty($value))
        {
            // 获取订单 id
            $ids = Db::name('OrderAddress')->where('name|tel|address', 'like', '%'.$value.'%')->column('order_id');

            // 避免空条件造成无效的错觉
            return empty($ids) ? [0] : $ids;
        }
        return $value;
    }

    /**
     * 基础条件处理
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-06-08
     * @desc    description
     * @param   [string]          $value    [条件值]
     * @param   [array]           $params   [输入参数]
     */
    public function WhereBaseGoodsInfo($value, $params = [])
    {
        if(!empty($value))
        {
            // 订单号
D
devil 已提交
535
            $ids = Db::name('Order')->where(['order_no'=>$value])->column('id');
D
devil 已提交
536 537 538 539 540 541 542 543 544 545 546 547 548 549

            // 获取订单详情搜索的订单 id
            if(empty($ids))
            {
                $ids = Db::name('OrderDetail')->where('title|model', 'like', '%'.$value.'%')->column('order_id');
            }

            // 避免空条件造成无效的错觉
            return empty($ids) ? [0] : $ids;
        }
        return $value;
    }
}
?>