RecordForm.php 28 KB

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