OrderList.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <?php
  2. namespace backendApi\modules\v1\models\lists\ba;
  3. use common\helpers\Cache;
  4. use common\helpers\Tool;
  5. use common\helpers\user\Info;
  6. use common\libs\dataList\DataListInterface;
  7. use common\models\BaApproachOrder;
  8. use common\models\BaApproachOrderGoods;
  9. use common\models\BaOrder;
  10. use common\models\BaOrderGoods;
  11. use common\models\ShopGoods;
  12. use common\models\BaUser;
  13. use common\libs\dataList\column\DateTime;
  14. use yii\data\Pagination;
  15. use yii\db\Query;
  16. class OrderList extends \common\libs\dataList\DataList implements DataListInterface
  17. {
  18. /**
  19. * 列表名称
  20. * @return string
  21. */
  22. public function getListName(){
  23. return 'BA订单列表';
  24. }
  25. /**
  26. * 列表筛选到的数据
  27. */
  28. public function dataHandle()
  29. {
  30. $orderQuery = BaOrder::find()
  31. ->alias('O')
  32. ->where($this->condition, $this->params)
  33. ->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')
  34. ->join('LEFT JOIN', BaUser::tableName() . ' AS U', 'U.ID=O.USER_ID')
  35. ->join('LEFT JOIN', BaOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=O.SN')
  36. ->join('LEFT JOIN', ShopGoods::tableName() . ' AS SG', 'SG.ID=OG.GOODS_ID')
  37. ->orderBy('O.CREATED_AT DESC');
  38. // 订单中间表只查询待支付和支付失败的订单
  39. $this->params[':NOT_PAID'] = \Yii::$app->params['orderStatus']['notPaid']['value']; // 待支付
  40. $this->params[':FAIL_PAID'] = \Yii::$app->params['orderStatus']['failPaid']['value']; // 支付失败
  41. $orderStandardQuery = BaApproachOrder::find()
  42. ->alias('O')
  43. ->where($this->condition . ' AND (O.STATUS = :NOT_PAID OR O.STATUS = :FAIL_PAID)', $this->params)
  44. ->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')
  45. ->join('LEFT JOIN', BaUser::tableName() . ' AS U', 'U.ID=O.USER_ID')
  46. ->join('LEFT JOIN', BaApproachOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=O.SN')
  47. ->join('LEFT JOIN', ShopGoods::tableName() . ' AS SG', 'SG.ID=OG.GOODS_ID')
  48. ->orderBy('O.CREATED_AT DESC');
  49. $queryAll = $orderQuery->union($orderStandardQuery, true);
  50. $query = (new Query())->from(['Q' => $queryAll])->select('Q.*')->distinct()->orderBy(['CREATED_AT' => SORT_DESC]);
  51. $totalCount = $query->count();
  52. $pagination = new Pagination(['totalCount' => $totalCount, 'pageSize' => \Yii::$app->request->get('pageSize')]);
  53. $lists = $query->offset($pagination->offset)->limit($pagination->limit)->all();
  54. $this->listData = [
  55. 'list' => $lists,
  56. 'currentPage'=>$pagination->page,
  57. 'totalPages'=>$pagination->pageCount,
  58. 'startNum' => $pagination->page * $pagination->pageSize + 1,
  59. 'totalCount' => $pagination->totalCount,
  60. 'pageSize' => $pagination->pageSize,
  61. ];
  62. foreach ($this->listData['list'] as $key => $value) {
  63. $CREATE_USER_ID = Info::getUserIdByUserName($value['CREATE_USER']);
  64. $this->listData['list'][$key]['DEC_USER_NAME'] = Info::getUserNameByUserId($value['DEC_ID']);
  65. $this->listData['list'][$key]['CREATE_USER_NAME'] = Info::getUserRealNameByUserId($CREATE_USER_ID);
  66. // $this->listData['list'][$key]['GOODS_NO'] = '';
  67. }
  68. }
  69. /**
  70. * 要展示和导出的所有字段
  71. * @return array
  72. */
  73. public function getColumn(){
  74. $regionConfig = Cache::getRegionConfig();
  75. if(!$this->columns){
  76. $this->columns = [
  77. 'ID' => null,
  78. 'DEC_SN' => null,
  79. 'USER_NAME' => [
  80. 'header' => 'Member code',//会员编号
  81. 'headerOther' => ['width' => '120'],
  82. ],
  83. 'DEC_USER_NAME' => [
  84. 'header' => 'Stockist', // 报单中心
  85. 'headerOther' => ['width' => '120'],
  86. ],
  87. 'CREATE_USER' => [
  88. 'header' => 'Creator No',//创建人编号
  89. 'headerOther' => ['width' => '120'],
  90. ],
  91. 'CREATE_USER_NAME' => [
  92. 'header' => 'Stockist Name',//创建人姓名
  93. 'headerOther' => ['width' => '120'],
  94. ],
  95. 'SN' => [
  96. 'header' => 'Order code',//订单号
  97. 'headerOther' => ['width' => '200'],
  98. ],
  99. // 'STATUS' => null,
  100. 'STATUS' => [
  101. 'header' => 'Status',//订单状态
  102. 'headerOther' => [
  103. 'width' => '110',
  104. ],
  105. 'value' => function ($row) {
  106. return \Yii::$app->params['orderStatus'][$row['STATUS']]['label'] ?? '';
  107. },
  108. ],
  109. 'SKU_CODE' => [
  110. 'header' => 'Product Code',//存货编码
  111. 'headerOther' => ['width' => '150'],
  112. ],
  113. 'GOODS_TITLE' => [
  114. 'header' => 'Product Name', // 存货名称
  115. 'headerOther' => ['width' => '200'],
  116. ],
  117. 'BUY_NUMS' => [
  118. 'header' => 'Qty',//数量
  119. 'headerOther' => ['width' => '100'],
  120. ],
  121. 'CONSIGNEE' => [
  122. 'header' => 'Recipient',//收货人
  123. 'headerOther' => [
  124. 'width' => '150',
  125. ],
  126. ],
  127. 'MOBILE' => [
  128. 'header' => 'Contact 1',//联系方式1
  129. 'headerOther' => [
  130. 'width' => '150',
  131. ],
  132. ],
  133. 'TEL' => [
  134. 'header' => 'Contact 2',//联系方式2
  135. ],
  136. 'PROVINCE' => [
  137. 'header' => 'State', // 州
  138. 'headerOther' => ['width' => '120'],
  139. 'value' => function ($row) use($regionConfig) {
  140. return $regionConfig[$row['PROVINCE']]['REGION_NAME'] ?? '';
  141. },
  142. ],
  143. 'CITY' => [
  144. 'header' => 'Local Government Area', // 地方政府
  145. 'headerOther' => ['width' => '120'],
  146. 'value' => function ($row) use($regionConfig) {
  147. return $regionConfig[$row['CITY']]['REGION_NAME'] ?? '';
  148. },
  149. ],
  150. 'COUNTY' => [
  151. 'header' => 'City', // 区
  152. 'headerOther' => ['width' => '120'],
  153. 'value' => function ($row) use($regionConfig) {
  154. return $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
  155. },
  156. ],
  157. // 'AREA' => [
  158. // 'header' => '地区',
  159. // // 用于导出
  160. // 'value' => function($row) use($regionConfig) {
  161. // $province = $regionConfig[$row['PROVINCE']]['REGION_NAME'] ?? '';
  162. // $city = $regionConfig[$row['CITY']]['REGION_NAME'] ?? '';
  163. // $county = $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
  164. // return $province.$city.$county;
  165. // },
  166. // // 用于前台显示
  167. // 'showValue' => function($row) {
  168. // $province = $regionConfig[$row['PROVINCE']]['REGION_NAME'] ?? '';
  169. // $city = $regionConfig[$row['CITY']]['REGION_NAME'] ?? '';
  170. // $county = $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
  171. // return '<div class="addr" title='.$province.$city.$county.'>'.$province.$city.$county.'</div>';
  172. // },
  173. // 'headerOther' => [
  174. // 'width' => '200'
  175. // ],
  176. // ],
  177. 'ADDRESS' => [
  178. 'header' => 'Detailed address',//详细地址
  179. 'headerOther' => [
  180. 'width' => '300',
  181. ],
  182. ],
  183. 'PERIOD_NUM' => [
  184. 'header' => 'Period',//期数
  185. ],
  186. 'ORDER_TYPE' => [
  187. 'header' => 'Order type',//订单类型
  188. 'headerOther' => ['width' => '120'],
  189. 'value' => function ($row) {
  190. switch ($row['ORDER_TYPE']) {
  191. case 'ZC':
  192. return 'Welcome pack';
  193. case 'FX':
  194. return in_array($row['PAY_TYPE'], ['cash', 'pay_stack']) ? 'Reselling': 'Points'; //'重消' : '积分'
  195. }
  196. },
  197. ],
  198. // 'WAREHOUSE' => [
  199. // 'header' => 'Delivery warehouse',//发货仓
  200. // ],
  201. 'CREATED_AT' => [
  202. 'header' => 'Creation time',//创建时间
  203. 'value' => function ($row) {
  204. return (new DateTime([
  205. 'value' => $row['CREATED_AT'],
  206. ]))->result();
  207. },
  208. 'headerOther' => ['width' => '190'],
  209. ],
  210. 'PAY_TYPE' => [
  211. 'header' => 'Pay type',// 支付方式
  212. 'value' => function ($row) {
  213. return ShopGoods::payTypes()[$row['PAY_TYPE']]['name'] ?? ShopGoods::payTypes()['cash']['name'];
  214. },
  215. 'headerOther' => ['width' => '190'],
  216. ],
  217. 'PAY_AT' => [
  218. 'header' => 'Payment time',//支付时间
  219. 'value' => function ($row) {
  220. return (new DateTime([
  221. 'value' => $row['PAY_AT'],
  222. ]))->result();
  223. },
  224. 'headerOther' => ['width' => '190'],
  225. ],
  226. 'DELIVERY_AT' => [
  227. 'header' => 'Delivery time',//发货时间
  228. 'value' => function ($row) {
  229. return (new DateTime([
  230. 'value' => $row['DELIVERY_AT'],
  231. ]))->result();
  232. },
  233. 'headerOther' => ['width' => '190'],
  234. ],
  235. 'REAL_PRICE' => [
  236. 'header' => 'Item Pricing',//商品单价
  237. 'headerOther' => [
  238. 'width' => '150',
  239. ],
  240. 'value' => function ($row) {
  241. return Tool::formatPrice($row['REAL_PRICE']);
  242. },
  243. 'valueOther' => function ($row) {
  244. return [
  245. 'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
  246. ];
  247. },
  248. ],
  249. 'REAL_PV' => [
  250. 'header' => 'Commodity amount',//商品金额
  251. 'headerOther' => [
  252. 'width' => '150',
  253. ],
  254. 'value' => function ($row) {
  255. return Tool::formatPrice($row['REAL_PV']);
  256. },
  257. 'valueOther' => function ($row) {
  258. return [
  259. 'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
  260. ];
  261. },
  262. ],
  263. 'PAY_FREIGHT' => [
  264. 'header' => 'Freight',//运费
  265. 'headerOther' => [
  266. 'width' => '150',
  267. ],
  268. 'value' => function ($row) {
  269. return Tool::formatPrice($row['FREIGHT']);
  270. },
  271. 'valueOther' => function ($row) {
  272. return [
  273. 'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
  274. ];
  275. },
  276. ],
  277. 'TAX_RATE' => [
  278. 'header' => 'Tax Rate',//税率
  279. 'headerOther' => [
  280. 'width' => '150',
  281. ],
  282. 'value' => function ($row) {
  283. return Tool::formatPrice($row['TAX_RATE']);
  284. },
  285. 'valueOther' => function ($row) {
  286. return [
  287. 'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
  288. ];
  289. },
  290. ],
  291. 'TAX_AMOUNT' => [
  292. 'header' => 'Tax',//税额
  293. 'headerOther' => [
  294. 'width' => '150',
  295. ],
  296. 'value' => function ($row) {
  297. return Tool::formatPrice(($row['REAL_PRICE'] - $row['REAL_PRICE'] / (1 + $row['TAX_RATE'] / 100)));
  298. },
  299. 'valueOther' => function ($row) {
  300. return [
  301. 'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
  302. ];
  303. },
  304. ],
  305. 'EXPRESS_COMPANY' => [
  306. 'header' => 'Courier Services Company',//快递公司
  307. 'headerOther' => ['width' => '150'],
  308. ],
  309. 'ORDER_TRACK_NO' => [
  310. 'header' => 'Courier Number',//快递单号
  311. 'headerOther' => ['width' => '200'],
  312. ],
  313. 'EXPRESS_TYPE' => [
  314. 'header' => 'Shipping Method',//发货方式
  315. 'headerOther' => ['width' => '150'],
  316. 'value' => function ($row) {
  317. return $row['EXPRESS_TYPE']==0 ? 'mailing ':' auto pick ';//'邮寄' : '自提'
  318. },
  319. ],
  320. 'FRONT_REMARK' => [
  321. 'header' => 'Member Notes',//会员备注
  322. 'headerOther' => [
  323. 'width' => '200',
  324. ],
  325. 'value' => function ($row) {
  326. return $row['FRONT_REMARK'];
  327. },
  328. 'showValue' => function ($row) {
  329. return '<div title="'.$row['FRONT_REMARK'].'" style="width:180px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">'.$row['FRONT_REMARK'].'</div>';
  330. },
  331. ],
  332. 'DELIVERY_STATUS' => null,
  333. 'DELIVERY_STATUS_NAME' => [
  334. 'header' => 'Shipment Status',//发货状态
  335. 'headerOther' => [
  336. 'width' => '110',
  337. ],
  338. 'value' => function ($row) {
  339. return \Yii::$app->params['deliveryStatus'][$row['DELIVERY_STATUS']]['label'] ?? '';
  340. },
  341. ],
  342. 'IS_AUTO' => [
  343. 'header' => 'Is Auto', // 是否自动
  344. 'value' => function ($row) {
  345. return $row['IS_AUTO'] == 1 ? 'Yes' : 'No';
  346. },
  347. ],
  348. ];
  349. }
  350. return $this->columns;
  351. }
  352. /**
  353. * 前台用于筛选的类型集合
  354. * @return mixed
  355. */
  356. public function getFilterTypes()
  357. {
  358. if(!$this->filterTypes){
  359. $this->filterTypes = [
  360. 'SN'=> ['name'=> 'Order No'],//订单编号
  361. 'USER_NAME'=> ['name'=> 'Member code'],//会员编号
  362. 'MOBILE'=> ['name'=> 'Contact 1'],//联系方式1
  363. 'ORDER_TYPE'=> ['name'=> 'Order Type'],
  364. 'PERIOD_NUM'=> ['name'=> 'Number of periods'],//期数
  365. 'CREATED_AT'=> ['name'=> 'Creation time', 'other'=>'date'],//创建时间
  366. 'STATUS'=> [
  367. 'name'=> 'Status',
  368. 'other'=> 'select',
  369. 'selectData'=> [
  370. ['id' => \Yii::$app->params['orderStatus']['paid']['value'], 'name' => \Yii::$app->params['orderStatus']['paid']['label']],
  371. ['id' => \Yii::$app->params['orderStatus']['notPaid']['value'], 'name' => \Yii::$app->params['orderStatus']['notPaid']['label']],
  372. ['id' => \Yii::$app->params['orderStatus']['failPaid']['value'], 'name' => \Yii::$app->params['orderStatus']['failPaid']['label']]
  373. ]
  374. ],
  375. 'IS_AUTO' => [
  376. 'name'=>'Is Auto',
  377. 'other'=> 'select',
  378. 'selectData'=> [
  379. ['id'=>1, 'name'=>'YES'],
  380. ['id'=>0, 'name'=>'NO'],
  381. ]
  382. ]
  383. ];
  384. }
  385. return $this->filterTypes;
  386. }
  387. }