| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- <?php
- namespace backendApi\modules\v1\models\lists\ba;
- use common\helpers\Cache;
- use common\helpers\Tool;
- use common\helpers\user\Info;
- use common\libs\dataList\DataListInterface;
- use common\models\BaApproachOrder;
- use common\models\BaApproachOrderGoods;
- use common\models\BaOrder;
- use common\models\BaOrderGoods;
- use common\models\ShopGoods;
- use common\models\BaUser;
- use common\libs\dataList\column\DateTime;
- use yii\data\Pagination;
- use yii\db\Query;
- class OrderList extends \common\libs\dataList\DataList implements DataListInterface
- {
- /**
- * 列表名称
- * @return string
- */
- public function getListName(){
- return 'BA订单列表';
- }
- /**
- * 列表筛选到的数据
- */
- public function dataHandle()
- {
- $orderQuery = BaOrder::find()
- ->alias('O')
- ->where($this->condition, $this->params)
- ->select('O.*,U.REAL_NAME,U.DEC_ID,SG.CATEGORY_TYPE,OG.REAL_PRICE,OG.TAX_RATE,OG.BUY_NUMS,OG.SKU_CODE,OG.GOODS_TITLE,OG.REAL_PV')
- ->join('LEFT JOIN', BaUser::tableName() . ' AS U', 'U.ID=O.USER_ID')
- ->join('LEFT JOIN', BaOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=O.SN')
- ->join('LEFT JOIN', ShopGoods::tableName() . ' AS SG', 'SG.ID=OG.GOODS_ID')
- ->orderBy('O.CREATED_AT DESC');
- // 订单中间表只查询待支付和支付失败的订单
- $this->params[':NOT_PAID'] = \Yii::$app->params['orderStatus']['notPaid']['value']; // 待支付
- $this->params[':FAIL_PAID'] = \Yii::$app->params['orderStatus']['failPaid']['value']; // 支付失败
- $orderStandardQuery = BaApproachOrder::find()
- ->alias('O')
- ->where($this->condition . ' AND (O.STATUS = :NOT_PAID OR O.STATUS = :FAIL_PAID)', $this->params)
- ->select('O.*,U.REAL_NAME,U.DEC_ID,SG.CATEGORY_TYPE,OG.REAL_PRICE,OG.TAX_RATE,OG.BUY_NUMS,OG.SKU_CODE,OG.GOODS_TITLE,OG.REAL_PV')
- ->join('LEFT JOIN', BaUser::tableName() . ' AS U', 'U.ID=O.USER_ID')
- ->join('LEFT JOIN', BaApproachOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=O.SN')
- ->join('LEFT JOIN', ShopGoods::tableName() . ' AS SG', 'SG.ID=OG.GOODS_ID')
- ->orderBy('O.CREATED_AT DESC');
- $queryAll = $orderQuery->union($orderStandardQuery, true);
- $query = (new Query())->from(['Q' => $queryAll])->select('Q.*')->distinct()->orderBy(['CREATED_AT' => SORT_DESC]);
- $totalCount = $query->count();
- $pagination = new Pagination(['totalCount' => $totalCount, 'pageSize' => \Yii::$app->request->get('pageSize')]);
- $lists = $query->offset($pagination->offset)->limit($pagination->limit)->all();
- $this->listData = [
- 'list' => $lists,
- 'currentPage'=>$pagination->page,
- 'totalPages'=>$pagination->pageCount,
- 'startNum' => $pagination->page * $pagination->pageSize + 1,
- 'totalCount' => $pagination->totalCount,
- 'pageSize' => $pagination->pageSize,
- ];
- foreach ($this->listData['list'] as $key => $value) {
- $CREATE_USER_ID = Info::getUserIdByUserName($value['CREATE_USER']);
- $this->listData['list'][$key]['DEC_USER_NAME'] = Info::getUserNameByUserId($value['DEC_ID']);
- $this->listData['list'][$key]['CREATE_USER_NAME'] = Info::getUserRealNameByUserId($CREATE_USER_ID);
- // $this->listData['list'][$key]['GOODS_NO'] = '';
- }
- }
- /**
- * 要展示和导出的所有字段
- * @return array
- */
- public function getColumn(){
- $regionConfig = Cache::getRegionConfig();
- if(!$this->columns){
- $this->columns = [
- 'ID' => null,
- 'DEC_SN' => null,
- 'USER_NAME' => [
- 'header' => 'Member code',//会员编号
- 'headerOther' => ['width' => '120'],
- ],
- 'DEC_USER_NAME' => [
- 'header' => 'Stockist', // 报单中心
- 'headerOther' => ['width' => '120'],
- ],
- 'CREATE_USER' => [
- 'header' => 'Creator No',//创建人编号
- 'headerOther' => ['width' => '120'],
- ],
- 'CREATE_USER_NAME' => [
- 'header' => 'Stockist Name',//创建人姓名
- 'headerOther' => ['width' => '120'],
- ],
- 'SN' => [
- 'header' => 'Order code',//订单号
- 'headerOther' => ['width' => '200'],
- ],
- // 'STATUS' => null,
- 'STATUS' => [
- 'header' => 'Status',//订单状态
- 'headerOther' => [
- 'width' => '110',
- ],
- 'value' => function ($row) {
- return \Yii::$app->params['orderStatus'][$row['STATUS']]['label'] ?? '';
- },
- ],
- 'SKU_CODE' => [
- 'header' => 'Product Code',//存货编码
- 'headerOther' => ['width' => '150'],
- ],
- 'GOODS_TITLE' => [
- 'header' => 'Product Name', // 存货名称
- 'headerOther' => ['width' => '200'],
- ],
- 'BUY_NUMS' => [
- 'header' => 'Qty',//数量
- 'headerOther' => ['width' => '100'],
- ],
- 'CONSIGNEE' => [
- 'header' => 'Recipient',//收货人
- 'headerOther' => [
- 'width' => '150',
- ],
- ],
- 'MOBILE' => [
- 'header' => 'Contact 1',//联系方式1
- 'headerOther' => [
- 'width' => '150',
- ],
- ],
- 'TEL' => [
- 'header' => 'Contact 2',//联系方式2
- ],
- 'PROVINCE' => [
- 'header' => 'State', // 州
- 'headerOther' => ['width' => '120'],
- 'value' => function ($row) use($regionConfig) {
- return $regionConfig[$row['PROVINCE']]['REGION_NAME'] ?? '';
- },
- ],
- 'CITY' => [
- 'header' => 'Local Government Area', // 地方政府
- 'headerOther' => ['width' => '120'],
- 'value' => function ($row) use($regionConfig) {
- return $regionConfig[$row['CITY']]['REGION_NAME'] ?? '';
- },
- ],
- 'COUNTY' => [
- 'header' => 'City', // 区
- 'headerOther' => ['width' => '120'],
- 'value' => function ($row) use($regionConfig) {
- return $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
- },
- ],
- // 'AREA' => [
- // 'header' => '地区',
- // // 用于导出
- // 'value' => function($row) use($regionConfig) {
- // $province = $regionConfig[$row['PROVINCE']]['REGION_NAME'] ?? '';
- // $city = $regionConfig[$row['CITY']]['REGION_NAME'] ?? '';
- // $county = $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
- // return $province.$city.$county;
- // },
- // // 用于前台显示
- // 'showValue' => function($row) {
- // $province = $regionConfig[$row['PROVINCE']]['REGION_NAME'] ?? '';
- // $city = $regionConfig[$row['CITY']]['REGION_NAME'] ?? '';
- // $county = $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
- // return '<div class="addr" title='.$province.$city.$county.'>'.$province.$city.$county.'</div>';
- // },
- // 'headerOther' => [
- // 'width' => '200'
- // ],
- // ],
- 'ADDRESS' => [
- 'header' => 'Detailed address',//详细地址
- 'headerOther' => [
- 'width' => '300',
- ],
- ],
- 'PERIOD_NUM' => [
- 'header' => 'Period',//期数
- ],
- 'ORDER_TYPE' => [
- 'header' => 'Order type',//订单类型
- 'headerOther' => ['width' => '120'],
- 'value' => function ($row) {
- switch ($row['ORDER_TYPE']) {
- case 'ZC':
- return 'Welcome pack';
- case 'FX':
- return in_array($row['PAY_TYPE'], ['cash', 'pay_stack']) ? 'Reselling': 'Points'; //'重消' : '积分'
- }
- },
- ],
- // 'WAREHOUSE' => [
- // 'header' => 'Delivery warehouse',//发货仓
- // ],
- 'CREATED_AT' => [
- 'header' => 'Creation time',//创建时间
- 'value' => function ($row) {
- return (new DateTime([
- 'value' => $row['CREATED_AT'],
- ]))->result();
- },
- 'headerOther' => ['width' => '190'],
- ],
- 'PAY_TYPE' => [
- 'header' => 'Pay type',// 支付方式
- 'value' => function ($row) {
- return ShopGoods::payTypes()[$row['PAY_TYPE']]['name'] ?? ShopGoods::payTypes()['cash']['name'];
- },
- 'headerOther' => ['width' => '190'],
- ],
- 'PAY_AT' => [
- 'header' => 'Payment time',//支付时间
- 'value' => function ($row) {
- return (new DateTime([
- 'value' => $row['PAY_AT'],
- ]))->result();
- },
- 'headerOther' => ['width' => '190'],
- ],
- 'DELIVERY_AT' => [
- 'header' => 'Delivery time',//发货时间
- 'value' => function ($row) {
- return (new DateTime([
- 'value' => $row['DELIVERY_AT'],
- ]))->result();
- },
- 'headerOther' => ['width' => '190'],
- ],
- 'REAL_PRICE' => [
- 'header' => 'Item Pricing',//商品单价
- 'headerOther' => [
- 'width' => '150',
- ],
- 'value' => function ($row) {
- return Tool::formatPrice($row['REAL_PRICE']);
- },
- 'valueOther' => function ($row) {
- return [
- 'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
- ];
- },
- ],
- 'REAL_PV' => [
- 'header' => 'Commodity amount',//商品金额
- 'headerOther' => [
- 'width' => '150',
- ],
- 'value' => function ($row) {
- return Tool::formatPrice($row['REAL_PV']);
- },
- 'valueOther' => function ($row) {
- return [
- 'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
- ];
- },
- ],
- 'PAY_FREIGHT' => [
- 'header' => 'Freight',//运费
- 'headerOther' => [
- 'width' => '150',
- ],
- 'value' => function ($row) {
- return Tool::formatPrice($row['FREIGHT']);
- },
- 'valueOther' => function ($row) {
- return [
- 'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
- ];
- },
- ],
- 'TAX_RATE' => [
- 'header' => 'Tax Rate',//税率
- 'headerOther' => [
- 'width' => '150',
- ],
- 'value' => function ($row) {
- return Tool::formatPrice($row['TAX_RATE']);
- },
- 'valueOther' => function ($row) {
- return [
- 'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
- ];
- },
- ],
- 'TAX_AMOUNT' => [
- 'header' => 'Tax',//税额
- 'headerOther' => [
- 'width' => '150',
- ],
- 'value' => function ($row) {
- return Tool::formatPrice(($row['REAL_PRICE'] - $row['REAL_PRICE'] / (1 + $row['TAX_RATE'] / 100)));
- },
- 'valueOther' => function ($row) {
- return [
- 'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
- ];
- },
- ],
- 'EXPRESS_COMPANY' => [
- 'header' => 'Courier Services Company',//快递公司
- 'headerOther' => ['width' => '150'],
- ],
- 'ORDER_TRACK_NO' => [
- 'header' => 'Courier Number',//快递单号
- 'headerOther' => ['width' => '200'],
- ],
- 'EXPRESS_TYPE' => [
- 'header' => 'Shipping Method',//发货方式
- 'headerOther' => ['width' => '150'],
- 'value' => function ($row) {
- return $row['EXPRESS_TYPE']==0 ? 'mailing ':' auto pick ';//'邮寄' : '自提'
- },
- ],
- 'FRONT_REMARK' => [
- 'header' => 'Member Notes',//会员备注
- 'headerOther' => [
- 'width' => '200',
- ],
- 'value' => function ($row) {
- return $row['FRONT_REMARK'];
- },
- 'showValue' => function ($row) {
- return '<div title="'.$row['FRONT_REMARK'].'" style="width:180px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">'.$row['FRONT_REMARK'].'</div>';
- },
- ],
- 'DELIVERY_STATUS' => null,
- 'DELIVERY_STATUS_NAME' => [
- 'header' => 'Shipment Status',//发货状态
- 'headerOther' => [
- 'width' => '110',
- ],
- 'value' => function ($row) {
- return \Yii::$app->params['deliveryStatus'][$row['DELIVERY_STATUS']]['label'] ?? '';
- },
- ],
- 'IS_AUTO' => [
- 'header' => 'Is Auto', // 是否自动
- 'value' => function ($row) {
- return $row['IS_AUTO'] == 1 ? 'Yes' : 'No';
- },
- ],
- ];
- }
- return $this->columns;
- }
- /**
- * 前台用于筛选的类型集合
- * @return mixed
- */
- public function getFilterTypes()
- {
- if(!$this->filterTypes){
- $this->filterTypes = [
- 'SN'=> ['name'=> 'Order No'],//订单编号
- 'USER_NAME'=> ['name'=> 'Member code'],//会员编号
- 'MOBILE'=> ['name'=> 'Contact 1'],//联系方式1
- 'ORDER_TYPE'=> ['name'=> 'Order Type'],
- 'PERIOD_NUM'=> ['name'=> 'Number of periods'],//期数
- 'CREATED_AT'=> ['name'=> 'Creation time', 'other'=>'date'],//创建时间
- 'STATUS'=> [
- 'name'=> 'Status',
- 'other'=> 'select',
- 'selectData'=> [
- ['id' => \Yii::$app->params['orderStatus']['paid']['value'], 'name' => \Yii::$app->params['orderStatus']['paid']['label']],
- ['id' => \Yii::$app->params['orderStatus']['notPaid']['value'], 'name' => \Yii::$app->params['orderStatus']['notPaid']['label']],
- ['id' => \Yii::$app->params['orderStatus']['failPaid']['value'], 'name' => \Yii::$app->params['orderStatus']['failPaid']['label']]
- ]
- ],
- 'IS_AUTO' => [
- 'name'=>'Is Auto',
- 'other'=> 'select',
- 'selectData'=> [
- ['id'=>1, 'name'=>'YES'],
- ['id'=>0, 'name'=>'NO'],
- ]
- ]
- ];
- }
- return $this->filterTypes;
- }
- }
|