RecordForm.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\models\v1;
  8. use app\models\AccountLog;
  9. use app\models\Goods;
  10. use app\models\Order;
  11. use app\models\OrderDetail;
  12. use app\models\OrderRefund;
  13. use app\models\ReOrder;
  14. use app\models\SaaSLeaguePriceLog;
  15. use app\models\SaasUser;
  16. use app\models\SaasUserPriceLog;
  17. use app\models\Store;
  18. use app\models\User;
  19. use app\modules\client\models\ApiModel;
  20. use yii\data\Pagination;
  21. class RecordForm extends ApiModel
  22. {
  23. public $store_id;
  24. public $user;
  25. // public $date;
  26. public $page = 1;
  27. public $type = -1; // -1: 全部, 1: 收入, 2: 支出
  28. public $limit = 15;
  29. public function rules()
  30. {
  31. return [
  32. // [['date'], 'date','format' => 'YYYY-mm'],
  33. // [['date'], 'default', 'value' => function () {
  34. // return date('Y-m', time());
  35. // }],
  36. [['store_id', 'page', 'type', 'limit'],'integer']
  37. ];
  38. }
  39. public function league_search()
  40. {
  41. $user_id = $this->user->id;
  42. $user = User::findOne($user_id);
  43. $saas_user = SaasUser::findOne(['mobile' => $user->binding]);
  44. $query = SaaSLeaguePriceLog::find()->where(['saas_user_id' => $saas_user->id, 'role' => SaaSLeaguePriceLog::ROLE_USER]);
  45. $count = $query->count();
  46. $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
  47. $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('id DESC')->asArray()->all();
  48. foreach ($list as & $arr) {
  49. $store = Store::findOne($arr['store_id']);
  50. if($arr['type'] == 0){
  51. $arr['icon'] = '+';
  52. $arr['desc'] = '【'.$store->name.'】'.'商城转赠';
  53. }elseif ($arr['type'] == 1) {
  54. if($arr['after'] > $arr['before']){
  55. $arr['icon'] = '+';
  56. }else{
  57. $arr['icon'] = '-';
  58. }
  59. $arr['desc'] = '平台修改';
  60. }elseif ($arr['type'] == 2) {
  61. $arr['icon'] = '+';
  62. $arr['desc'] = '【'.$store->name.'】'.'消费获赠';
  63. }elseif ($arr['type'] == 3) {
  64. $arr['icon'] = '+';
  65. $arr['desc'] = '【'.$store->name.'】'.'订单取消返回';
  66. }elseif ($arr['type'] == 4) {
  67. $arr['icon'] = '-';
  68. $arr['desc'] = '【'.$store->name.'】'.'下单抵扣';
  69. }
  70. $arr['show_desc'] = $arr['desc'];
  71. $arr['show_time'] = date('Y-m-d H:i',$arr['addtime']);
  72. $arr['show_price'] = $arr['icon'] . $arr['league_price'];
  73. }
  74. return [
  75. 'code' => 0,
  76. 'msg' => 'success',
  77. 'data' => [
  78. 'league_price' => $saas_user->league_price,
  79. 'list' => $list,
  80. 'page_count' => $pagination->getPageCount(),
  81. ]
  82. ];
  83. }
  84. public function search()
  85. {
  86. if (!$this->validate()) {
  87. return [
  88. 'code' => 1,
  89. 'msg' => $this->getErrorSummary(false)[0],
  90. ];
  91. }
  92. $query = AccountLog::find()->where([
  93. 'store_id' => $this->store_id,
  94. 'user_id' => $this->user->id,
  95. 'type' => [2,19], // 余额
  96. ]);
  97. if ($this->type > -1 && in_array($this->type, [1, 2])) {
  98. $query->andWhere(['log_type' => $this->type]);
  99. }
  100. $count = $query->count();
  101. $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
  102. $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('created_at DESC')->asArray()->all();
  103. foreach ($list as $key => &$value) {
  104. $value['date'] = date('Y-m-d H:i:s', $value['created_at']);
  105. $value['content'] = $value['desc'];
  106. if ($value['log_type'] == 1) {
  107. // 收入
  108. $value['price'] = '+' . $value['amount'];
  109. if (strpos($value['desc'], '管理员') !== false) {
  110. $value['content'] = '管理员后台充值';
  111. }
  112. if (strpos($value['desc'], '充值余额') !== false) {
  113. $value['content'] = '充值余额';
  114. }
  115. // if (strpos($value['desc'], '商城售后订单退款') !== false) {
  116. // $value['content'] = '商城售后订单退款';
  117. // }
  118. } else {
  119. // 支出
  120. $value['price'] = '-' . $value['amount'];
  121. if (strpos($value['desc'], '管理员') !== false) {
  122. $value['content'] = '管理员后台扣除';
  123. }
  124. if (strpos($value['desc'], '商城余额') !== false) {
  125. $value['content'] = '商城下单';
  126. }
  127. if (strpos($value['desc'], '当面付余额') !== false) {
  128. $value['content'] = '当面付';
  129. }
  130. if (strpos($value['desc'], '购买会员') !== false) {
  131. $value['content'] = '购买会员';
  132. }
  133. }
  134. }
  135. return [
  136. 'code' => 0,
  137. 'msg' => 'success',
  138. 'data' => [
  139. 'list' => $list,
  140. 'page_count' => $pagination->getPageCount(),
  141. ]
  142. ];
  143. }
  144. /**
  145. * @return array
  146. * @throws \yii\db\Exception
  147. */
  148. public function search1()
  149. {
  150. if (!$this->validate()) {
  151. return [
  152. 'code' => 1,
  153. 'msg' => $this->getErrorSummary(false)[0],
  154. ];
  155. }
  156. // 搜索置顶月份的充值记录及余额消费记录
  157. $date = $this->date;
  158. $start = strtotime($date);
  159. $end = strtotime(date('Y-m-t', $start)) + 86400;
  160. $sql = $this->getSql();
  161. $select = "SELECT * ";
  162. $where = " WHERE al.created_at >= {$start} AND al.created_at <= {$end}";
  163. $list = \Yii::$app->db->createCommand($select . $sql . $where . " ORDER BY al.created_at DESC")->queryAll();
  164. foreach ($list as $index => $value) {
  165. if (in_array($value['order_type'], ['log'])) {
  166. if (strpos($value['content'],'充值余额') !== false) {
  167. $list[$index]['flag'] = 0;
  168. $list[$index]['price'] = '+' . (floatval($value['pay_price']) + floatval($value['send_price']));
  169. $list[$index]['content'] = '充值';
  170. } else {
  171. $list[$index]['flag'] = 1;
  172. $list[$index]['price'] = '-' . (floatval($value['pay_price']) + floatval($value['send_price']));
  173. $list[$index]['content'] = '扣除';
  174. }
  175. } elseif (in_array($value['order_type'], ['s_re'])) {
  176. $list[$index]['flag'] = 2;
  177. $list[$index]['price'] = '+' . (floatval($value['pay_price']) + floatval($value['send_price']));
  178. $list[$index]['content'] = "订单退款";
  179. } else {
  180. $list[$index]['flag'] = 1;
  181. $list[$index]['price'] = '-' . floatval($value['pay_price']);
  182. if ($value['order_type'] == 's') {
  183. $goods = Goods::find()->alias('g')->where([
  184. 'g.store_id' => $this->store_id
  185. ])->leftJoin(['od' => OrderDetail::tableName()],'od.goods_id=g.id')
  186. ->andWhere(['od.order_id' => $value['id']])->select(['g.name'])->asArray()->column();
  187. $goods_str = implode(',', $goods);
  188. $list[$index]['content'] = "消费-商城订单{$goods_str}";
  189. }
  190. }
  191. $list[$index]['date'] = date('Y-m-d H:i:s', $value['created_at']);
  192. }
  193. return [
  194. 'code' => 0,
  195. 'msg' => 'success',
  196. 'data' => [
  197. 'list' => $list,
  198. 'date' => $date
  199. ]
  200. ];
  201. }
  202. //充值记录
  203. public function rechargeOrder() {
  204. $query = ReOrder::find()->where([
  205. 'is_pay' => 1,
  206. 'is_delete' => 0,
  207. 'store_id' => $this->store_id,
  208. 'user_id' => $this->user->id,
  209. ])->orderBy('id DESC');
  210. $data = pagination_make($query);
  211. return [
  212. 'code' => 0,
  213. 'data' => $data,
  214. // 'sql' => $query->createCommand()->getRawSql(),
  215. ];
  216. }
  217. public function yifang()
  218. {
  219. if (!$this->validate()) {
  220. return $this->errorResponse;
  221. }
  222. //搜索置顶月份的充值记录及余额消费记录
  223. $date = $this->date;
  224. $start = strtotime($date);
  225. $end = strtotime(date('Y-m-t', $start)) + 86400;
  226. $start=date('Y-m-d',$start);
  227. $end=date('Y-m-d',$end);
  228. $list = Fyorder::find()->where(['user_id'=>$this->user->id,'type'=>1])->andWhere(['<', 'addtime', $end])->andWhere(['>=', 'addtime', $start])->orderBy('addtime desc')->asArray()->all();
  229. foreach ($list as $index => $value) {
  230. $list[$index]['flag'] = 0;
  231. $list[$index]['price'] = '+' . round(floatval($value['money']),2);
  232. $list[$index]['content'] = "优惠券释放";
  233. $list[$index]['date'] = $value['addtime'];
  234. }
  235. $yi = $list[0]['yifan'];
  236. if(!$yi){
  237. $yi=0;
  238. }
  239. return new ApiResponse(0,'success',[
  240. 'list' => $list,
  241. 'date' => $date,
  242. 'yi'=>$yi
  243. ]);
  244. }
  245. private function getSql2($user_id,$confirm_time,$store_id)
  246. {
  247. $s_table = Order::tableName();
  248. $ms_table = MsOrder::tableName();
  249. $pt_table = PtOrder::tableName();
  250. $yy_table = YyOrder::tableName();
  251. $order_share_table = OrderShare::tableName();
  252. $sql_s = "(
  253. SELECT
  254. 's' AS `order_type`,
  255. `id`,
  256. `order_no`,
  257. `is_pay`,
  258. `pay_price`,
  259. `is_price`,
  260. `user_id`,
  261. `apply_delete`,
  262. `addtime`,
  263. `parent_id` AS `parent_id_1`,
  264. `parent_id_1` AS `parent_id_2`,
  265. `parent_id_2` AS `parent_id_3`,
  266. `first_price`,
  267. `second_price`,
  268. `third_price`,
  269. `rebate`,
  270. `store_id`,
  271. `is_show`,
  272. `is_confirm`,
  273. `confirm_time`,
  274. `fyjine`,
  275. `fysingle`,
  276. `mch_fyjine`,
  277. `mch_fysingle`
  278. FROM
  279. {$s_table}
  280. WHERE
  281. (`is_pay` = 1)
  282. AND (`is_confirm` = 1)
  283. AND (`user_id` = {$user_id})
  284. AND (`is_delete` = 0)
  285. AND (`is_sale` = 1)
  286. AND (`confirm_time` <= {$confirm_time})
  287. AND (store_id = {$store_id})
  288. )";
  289. $sql_ms = "(
  290. SELECT
  291. 'ms' AS `order_type`,
  292. `id`,
  293. `order_no`,
  294. `is_pay`,
  295. `pay_price`,
  296. `is_price`,
  297. `user_id`,
  298. `apply_delete`,
  299. `addtime`,
  300. `parent_id` AS `parent_id_1`,
  301. `parent_id_1` AS `parent_id_2`,
  302. `parent_id_2` AS `parent_id_3`,
  303. `first_price`,
  304. `second_price`,
  305. `third_price`,
  306. `rebate`,
  307. `store_id`,
  308. `is_show`,
  309. `is_confirm`,
  310. `confirm_time`,
  311. `fyjine`,
  312. `fysingle`,
  313. `mch_fyjine`,
  314. `mch_fysingle`
  315. FROM
  316. {$ms_table}
  317. WHERE
  318. (`is_pay` = 1)
  319. AND (`is_confirm` = 1)
  320. AND (`user_id` = {$user_id})
  321. AND (`is_delete` = 0)
  322. AND (`is_sale` = 1)
  323. AND (`confirm_time` <= {$confirm_time})
  324. AND (store_id = {$store_id})
  325. )";
  326. $sql_pt = "(
  327. SELECT
  328. 'pt' AS `order_type`,
  329. `pt`.`id`,
  330. `pt`.`order_no`,
  331. `pt`.`is_pay`,
  332. `pt`.`pay_price`,
  333. `pt`.`is_price`,
  334. `pt`.`user_id`,
  335. `pt`.`apply_delete`,
  336. `pt`.addtime,
  337. `os`.`parent_id_1`,
  338. `os`.`parent_id_2`,
  339. `os`.`parent_id_3`,
  340. `os`.`first_price`,
  341. `os`.`second_price`,
  342. `os`.`third_price`,
  343. `os`.`rebate`,
  344. `pt`.`store_id`,
  345. `pt`.`is_show`,
  346. `pt`.`is_confirm`,
  347. `pt`.`confirm_time`,
  348. `pt`.`fyjine`,
  349. `pt`.`fysingle`,
  350. `pt`.`mch_fyjine`,
  351. `pt`.`mch_fysingle`
  352. FROM
  353. {$pt_table} `pt`
  354. LEFT JOIN {$order_share_table} `os` ON pt.id = os.order_id AND `os`.`type` = 0
  355. WHERE
  356. (`pt`.`is_pay` = 1)
  357. AND (`pt`.`is_confirm` = 1)
  358. AND (`pt`.`user_id` = {$user_id})
  359. AND (`pt`.`is_delete` = 0)
  360. AND (`pt`.`confirm_time` <= {$confirm_time})
  361. AND (pt.store_id = {$store_id})
  362. )";
  363. $sql_yy = "(
  364. SELECT
  365. 'yy' AS `order_type`,
  366. `yy`.`id`,
  367. `yy`.`order_no`,
  368. `yy`.`is_pay`,
  369. `yy`.`pay_price`,
  370. `yy`.`is_use` is_price,
  371. `yy`.`user_id`,
  372. `yy`.`apply_delete`,
  373. `yy`.addtime,
  374. `os`.`parent_id_1`,
  375. `os`.`parent_id_2`,
  376. `os`.`parent_id_3`,
  377. `os`.`first_price`,
  378. `os`.`second_price`,
  379. `os`.`third_price`,
  380. `os`.`rebate`,
  381. `yy`.`store_id`,
  382. `yy`.`is_show`,
  383. `yy`.`is_use`,
  384. `yy`.`use_time`,
  385. `yy`.`fyjine`,
  386. `yy`.`fysingle`,
  387. `yy`.`mch_fyjine`,
  388. `yy`.`mch_fysingle`
  389. FROM
  390. {$yy_table} `yy`
  391. LEFT JOIN {$order_share_table} `os` ON os.order_id = yy.id AND `os`.`type` = 1
  392. WHERE
  393. (`yy`.`is_pay` = 1)
  394. AND (`yy`.`is_use` = 1)
  395. AND (`yy`.`is_delete` = 0)
  396. AND (`yy`.`user_id` = {$user_id})
  397. AND (`yy`.`use_time` <= {$confirm_time})
  398. AND (yy.store_id = {$store_id})
  399. )";
  400. $sql = " FROM (
  401. SELECT * FROM ( {$sql_s} UNION {$sql_ms} UNION {$sql_pt} UNION {$sql_yy} ) AS `l`
  402. WHERE
  403. `l`.`store_id` = 1
  404. ) AS `al` ";
  405. return $sql;
  406. }
  407. public function daifang()
  408. {
  409. if (!$this->validate()) {
  410. return $this->errorResponse;
  411. }
  412. $store=Store::findOne(['id'=>$this->store_id]);
  413. $now=time();
  414. //计算自动确认收货
  415. $com=(3600*24)*$store->after_sale_time;
  416. //是否超过售后期
  417. $confirm_time=$now-$com;
  418. $xfybl=round(($store->xfybl)/1000,2);//消费购物返佣比例
  419. $sfybl=round(($store->sfybl)/1000,2);//商家返佣比例
  420. //查询客户返佣订单
  421. $select = "SELECT al.*";
  422. $sql = $this->getSql2($this->user->id,$confirm_time,$this->store_id);
  423. $list = \Yii::$app->db->createCommand($select . $sql . "ORDER BY al.created_at DESC")->queryAll();
  424. $payjine=0;
  425. foreach($list as $v){
  426. $payjine += $v['pay_price'];
  427. }
  428. //作为客户订单返佣金额
  429. $oprice=round($payjine,2);
  430. //购买加速金额
  431. $ljine=LevelOrder::find()->where(['is_pay'=>1,'user_id'=>$this->user->id])->SUM('pay_price');
  432. //若用户为商户
  433. $mch_id=Mch::find()->where(['user_id'=>$this->user->id])->select('id')->asArray()->all();
  434. $mjine=0;
  435. if($mch_id){
  436. //查询商户订单
  437. $str=array();
  438. foreach($mch_id as $v){
  439. $str[]=$v['id'];
  440. }
  441. $owhere=array();
  442. $owhere['is_pay']=1;
  443. $owhere['is_confirm']=1;
  444. $owhere['confirm_time']<=$confirm_time;
  445. $mjine=Order::find()->where($owhere)->andWhere(['in','mch_id',$str])->SUM('pay_price');
  446. $mjine=round($mjine,2);
  447. }
  448. $allprice=round(($oprice*$xfybl)+$ljine,2);
  449. $mjine=round($mjine*$sfybl,2);
  450. //全返金额
  451. $allprice=$allprice+$mjine;
  452. if (!$allprice) {
  453. $allprice=0;
  454. }
  455. //全返金额$order->pay_price-$order->express_price;
  456. $yifan=Fyorder::find()->where(['user_id'=>$this->user->id])->select('yifan,zonge')->limit(1)->orderBy('addtime desc')->all();
  457. //$zonge=round($yifan[0]->zonge,2);
  458. $yifan=round($yifan[0]->yifan,2);
  459. if(!$yifan){
  460. $yifan=0;
  461. }
  462. //$allprice=$zonge-$yifan;
  463. $allprice=$allprice-$yifan;
  464. //搜索置顶月份的充值记录及余额消费记录
  465. $date = $this->date;
  466. $start = strtotime($date);
  467. $end = strtotime(date('Y-m-t', $start)) + 86400;
  468. $end = strtotime(date('Y-m-t', $start)) + 86400;
  469. $start=date('Y-m-d',$start);
  470. $end=date('Y-m-d',$end);
  471. $list = Fyorder::find()->where(['user_id'=>$this->user->id])->andWhere(['<', 'addtime', $end])->andWhere(['>=', 'addtime', $start])->orderBy('addtime desc')->asArray()->all();
  472. foreach ($list as $index => $value) {
  473. if($value['type']==1){
  474. $list[$index]['flag'] = 1;
  475. $list[$index]['price'] = '-' . round(floatval($value['money']),2);
  476. $list[$index]['daifan'] = $value['zonge']-$value['yifan'];
  477. $list[$index]['content'] = "优惠券释放";
  478. $list[$index]['date'] = $value['addtime'];
  479. }elseif($value['type']==2){
  480. $list[$index]['flag'] = 0;
  481. $list[$index]['price'] = '+' . round(floatval($value['money']),2);
  482. $list[$index]['daifan'] = $value['zonge']-$value['yifan'];
  483. $list[$index]['content'] = "优惠券释放";
  484. $list[$index]['date'] = $value['addtime'];
  485. }
  486. }
  487. return new ApiResponse(0,'success',[
  488. 'list' => $list,
  489. 'date' => $date,
  490. 'dai'=>$allprice
  491. ]);
  492. }
  493. public function getSql()
  494. {
  495. // $r_table = ReOrder::tableName();
  496. $s_table = Order::tableName();
  497. // $ms_table = MsOrder::tableName();
  498. // $pt_table = PtOrder::tableName();
  499. // $yy_table = YyOrder::tableName();
  500. $s_refund_table = OrderRefund::tableName();
  501. // $ms_refund_table = MsOrderRefund::tableName();
  502. // $pt_refund_table = PtOrderRefund::tableName();
  503. // $yy_refund_table = YyOrder::tableName();
  504. // $pondTable = PondLog::tableName();
  505. // $scratchTable = ScratchLog::tableName();
  506. $logTable = AccountLog::tableName();
  507. // $query_r = "(
  508. // SELECT
  509. // 'r' AS order_type,
  510. // id,
  511. // created_at,
  512. // pay_price,
  513. // pay_type,
  514. // send_price,
  515. // '' AS content
  516. // FROM {$r_table}
  517. // WHERE store_id = {$this->store_id}
  518. // AND user_id = {$this->user->id}
  519. // AND is_delete = 0
  520. // AND is_pay = 1
  521. // )";
  522. $query_s = "(
  523. SELECT
  524. 's' AS order_type,
  525. id,
  526. created_at,
  527. pay_price,
  528. 0 AS pay_type,
  529. 0 AS send_price,
  530. '' AS content
  531. FROM {$s_table}
  532. WHERE store_id = {$this->store_id}
  533. AND user_id = {$this->user->id}
  534. AND is_delete = 0
  535. AND trade_status != 1
  536. AND is_pay = 1
  537. AND pay_type = 3
  538. AND is_show = 1
  539. )";
  540. // $query_ms = "(
  541. // SELECT
  542. // 'ms' AS order_type,
  543. // id,
  544. // created_at,
  545. // pay_price,
  546. // 0 AS pay_type,
  547. // 0 AS send_price,
  548. // '' AS content
  549. // FROM {$ms_table}
  550. // WHERE store_id = {$this->store_id}
  551. // AND user_id = {$this->user->id}
  552. // AND is_delete = 0
  553. // AND is_cancel = 0
  554. // AND is_pay = 1
  555. // AND pay_type = 3
  556. // AND is_show = 1
  557. // )";
  558. // $query_pt = "(
  559. // SELECT
  560. // 'pt' AS order_type,
  561. // id,
  562. // created_at,
  563. // pay_price,
  564. // 0 AS pay_type,
  565. // 0 AS send_price,
  566. // '' AS content
  567. // FROM {$pt_table}
  568. // WHERE store_id = {$this->store_id}
  569. // AND user_id = {$this->user->id}
  570. // AND is_delete = 0
  571. // AND is_cancel = 0
  572. // AND is_pay = 1
  573. // AND pay_type = 3
  574. // AND is_show = 1
  575. // )";
  576. //
  577. // $query_yy = "(
  578. // SELECT
  579. // 'yy' AS order_type,
  580. // id,
  581. // created_at,
  582. // pay_price,
  583. // 0 AS pay_type,
  584. // 0 AS send_price,
  585. // '' AS content
  586. // FROM {$yy_table}
  587. // WHERE store_id = {$this->store_id}
  588. // AND user_id = {$this->user->id}
  589. // AND is_delete = 0
  590. // AND is_cancel = 0
  591. // AND is_pay = 1
  592. // AND pay_type = 2
  593. // AND is_show = 1
  594. // )";
  595. $query_s_re = "(
  596. SELECT
  597. 's_re' AS order_type,
  598. ore.id,
  599. ore.created_at,
  600. ore.refund_price AS pay_price,
  601. 0 AS pay_type,
  602. 0 AS send_price,
  603. '' AS content
  604. FROM {$s_refund_table} AS ore
  605. LEFT JOIN {$s_table} AS o ON o.id = ore.order_id
  606. WHERE ore.store_id = {$this->store_id}
  607. AND ore.is_delete = 0
  608. AND ore.type = 1
  609. AND ore.status = 1
  610. AND o.pay_type = 3
  611. AND ore.user_id = {$this->user->id}
  612. AND o.is_show = 1
  613. )";
  614. // $query_ms_re = "(
  615. // SELECT
  616. // 'ms_re' AS order_type,
  617. // ore.id,
  618. // ore.created_at,
  619. // ore.refund_price AS pay_price,
  620. // 0 AS pay_type,
  621. // 0 AS send_price,
  622. // '' AS content
  623. // FROM {$ms_refund_table} AS ore
  624. // LEFT JOIN {$ms_table} AS o ON o.id = ore.order_id
  625. // WHERE ore.store_id = {$this->store_id}
  626. // AND ore.is_delete = 0
  627. // AND ore.type = 1
  628. // AND ore.status = 1
  629. // AND o.pay_type = 3
  630. // AND ore.user_id = {$this->user->id}
  631. // AND o.is_show = 1
  632. // )";
  633. //
  634. // $query_pt_re = "(
  635. // SELECT
  636. // 'pt_re' AS order_type,
  637. // ore.id,
  638. // ore.created_at,
  639. // ore.refund_price AS pay_price,
  640. // 0 AS pay_type,
  641. // 0 AS send_price,
  642. // '' AS content
  643. // FROM {$pt_refund_table} AS ore
  644. // LEFT JOIN {$pt_table} AS o ON o.id = ore.order_id
  645. // WHERE ore.store_id = {$this->store_id}
  646. // AND ore.is_delete = 0
  647. // AND ore.type = 1
  648. // AND ore.status = 1
  649. // AND o.pay_type = 3
  650. // AND ore.user_id = {$this->user->id}
  651. // AND o.is_show = 1
  652. // )";
  653. //
  654. // $query_yy_re = "(
  655. // SELECT
  656. // 'yy_re' AS order_type,
  657. // ore.id,
  658. // ore.refund_time AS addtime,
  659. // ore.pay_price,
  660. // 0 AS pay_type,
  661. // 0 AS send_price,
  662. // '' AS content
  663. // FROM {$yy_refund_table} AS ore
  664. // WHERE ore.store_id = {$this->store_id}
  665. // AND ore.user_id = {$this->user->id}
  666. // AND ore.is_pay = 1
  667. // AND ore.is_delete = 0
  668. // AND ore.pay_type = 2
  669. // AND ore.is_cancel = 0
  670. // AND ore.is_refund = 1
  671. // AND ore.is_show = 1
  672. // )";
  673. $query_log = "(
  674. SELECT
  675. 'log' AS order_type,
  676. lt.id,
  677. lt.created_at,
  678. lt.amount AS pay_price,
  679. 0 AS pay_type,
  680. 0 AS send_price,
  681. lt.desc AS content
  682. FROM {$logTable} AS lt
  683. WHERE lt.store_id = {$this->store_id}
  684. AND lt.type = 2
  685. AND lt.order_type = 0
  686. AND lt.user_id = {$this->user->id}
  687. )";
  688. // $pondLog = "(
  689. // SELECT
  690. // 'pond' AS order_type,
  691. // p.id,
  692. // p.created_at as addtime,
  693. // p.price AS pay_price,
  694. // 0 AS pay_type,
  695. // 0 AS send_price,
  696. // '' AS content
  697. // FROM {$pondTable} AS p
  698. // WHERE p.store_id = {$this->store_id}
  699. // AND p.type = 1
  700. // AND p.status = 1
  701. // AND p.user_id = {$this->user->id}
  702. // )";
  703. //
  704. // $scratchLog = "(
  705. // SELECT
  706. // 'scratch' AS order_type,
  707. // id,
  708. // create_time as addtime,
  709. // price AS pay_price,
  710. // 0 AS pay_type,
  711. // 0 AS send_price,
  712. // '' AS content
  713. // FROM {$scratchTable}
  714. // WHERE store_id = {$this->store_id}
  715. // AND type = 1
  716. // AND status = 2
  717. // AND user_id = {$this->user->id}
  718. // )";
  719. // $sql = " FROM (
  720. // {$query_r}
  721. // UNION {$query_s}
  722. // UNION {$query_ms}
  723. // UNION {$query_pt}
  724. // UNION {$query_yy}
  725. // UNION {$query_s_re}
  726. // UNION {$query_ms_re}
  727. // UNION {$query_pt_re}
  728. // UNION {$query_yy_re}
  729. // UNION {$query_log}
  730. // UNION {$pondLog}
  731. // UNION {$scratchLog}
  732. // ) AS al ";
  733. $sql = " FROM (
  734. {$query_s}
  735. UNION {$query_s_re}
  736. UNION {$query_log}
  737. ) AS al ";
  738. return $sql;
  739. }
  740. }