| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\models;
- use app\models\AccountLog;
- use app\models\Goods;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\models\OrderRefund;
- use app\models\ReOrder;
- use app\models\SaaSLeaguePriceLog;
- use app\models\SaasUser;
- use app\models\Store;
- use app\models\User;
- use yii\data\Pagination;
- class RecordForm extends ApiModel
- {
- public $store_id;
- public $user;
- // public $date;
- public $page = 1;
- public $type = -1; // -1: 全部, 1: 收入, 2: 支出
- public $log_type;
- public $limit = 15;
- public function rules()
- {
- return [
- // [['date'], 'date','format' => 'YYYY-mm'],
- // [['date'], 'default', 'value' => function () {
- // return date('Y-m', time());
- // }],
- [['store_id', 'page', 'type', 'limit', 'log_type'],'integer']
- ];
- }
- public function league_search()
- {
- $saas_user = SaasUser::findOne(['id' => get_saas_user_id()]);
- $query = SaaSLeaguePriceLog::find()->where(['saas_user_id' => $saas_user->id, 'role' => 0])
- ->andWhere(['<>', 'type', 6]);
- if ($this->type == 1) {
- $query->andWhere('`after` > `before`');
- }
- if ($this->type == 2) {
- $query->andWhere('`before` > `after`');
- }
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
- //兼容前端传log_type 区分加减
- $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";
- if (in_array($this->type, [1, 2])) {
- $sql .= " AND l.log_type = {$this->type}";
- }
- $sql .= " AND l.role = 0 ORDER BY l.id desc LIMIT {$pagination->limit} OFFSET {$pagination->offset} ";
- $list = \Yii::$app->db->createCommand($sql)->queryAll();
- // $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('addtime DESC')->asArray()->all();
- foreach ($list as & $arr) {
- $store = Store::findOne($arr['store_id']);
- if($arr['type'] == 0){
- $arr['log_type'] = 1;
- $arr['icon'] = '+';
- $arr['desc'] = '【'.$store->name.'】'.'商城转赠';
- }elseif ($arr['type'] == 1) {
- if($arr['after'] > $arr['before']){
- $arr['log_type'] = 1;
- $arr['icon'] = '+';
- }else{
- $arr['log_type'] = 2;
- $arr['icon'] = '-';
- }
- $arr['desc'] = '平台修改';
- }elseif ($arr['type'] == 2) {
- $arr['log_type'] = 1;
- $arr['icon'] = '+';
- $arr['desc'] = '【'.$store->name.'】'.'消费获赠';
- }elseif ($arr['type'] == 3) {
- $arr['log_type'] = 1;
- $arr['icon'] = '+';
- $arr['desc'] = '【'.$store->name.'】'.'订单取消返回';
- }elseif ($arr['type'] == 4) {
- $arr['log_type'] = 2;
- $arr['icon'] = '-';
- $arr['desc'] = '【'.$store->name.'】'.'下单抵扣';
- }
- $arr['show_desc'] = $arr['desc'];
- $arr['show_time'] = date('Y-m-d H:i',$arr['addtime']);
- $arr['show_price'] = $arr['icon'] . $arr['league_price'];
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'league_price' => $saas_user->league_price,
- 'list' => $list,
- 'page_count' => $pagination->getPageCount(),
- ]
- ];
- }
- public function search()
- {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $query = AccountLog::find()->where([
- 'store_id' => $this->store_id,
- 'user_id' => $this->user->id,
- 'type' => 2, // 余额
- ]);
- if ($this->type > -1 && in_array($this->type, [1, 2])) {
- $query->andWhere(['log_type' => $this->type]);
- }
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
- $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('created_at DESC')->asArray()->all();
- foreach ($list as $key => &$value) {
- $value['date'] = date('Y-m-d H:i:s', $value['created_at']);
- $value['content'] = $value['desc'];
- if ($value['log_type'] == 1) {
- // 收入
- $value['price'] = '+' . $value['amount'];
- if (strpos($value['desc'], '管理员') !== false) {
- $value['content'] = '管理员后台充值';
- }
- if (strpos($value['desc'], '充值余额') !== false) {
- $value['content'] = '充值余额';
- }
- // if (strpos($value['desc'], '商城售后订单退款') !== false) {
- // $value['content'] = '商城售后订单退款';
- // }
- } else {
- // 支出
- $value['price'] = '-' . $value['amount'];
- if (strpos($value['desc'], '管理员') !== false) {
- $value['content'] = '管理员后台扣除';
- }
- if (strpos($value['desc'], '商城余额') !== false) {
- $value['content'] = '商城下单';
- }
- if (strpos($value['desc'], '当面付余额') !== false) {
- $value['content'] = '当面付';
- }
- if (strpos($value['desc'], '购买会员') !== false) {
- $value['content'] = '购买会员';
- }
- }
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $list,
- 'page_count' => $pagination->getPageCount(),
- ]
- ];
- }
- /**
- * @return array
- * @throws \yii\db\Exception
- */
- public function search1()
- {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- // 搜索置顶月份的充值记录及余额消费记录
- $date = $this->date;
- $start = strtotime($date);
- $end = strtotime(date('Y-m-t', $start)) + 86400;
- $sql = $this->getSql();
- $select = "SELECT * ";
- $where = " WHERE al.created_at >= {$start} AND al.created_at <= {$end}";
- $list = \Yii::$app->db->createCommand($select . $sql . $where . " ORDER BY al.created_at DESC")->queryAll();
- foreach ($list as $index => $value) {
- if (in_array($value['order_type'], ['log'])) {
- if (strpos($value['content'],'充值余额') !== false) {
- $list[$index]['flag'] = 0;
- $list[$index]['price'] = '+' . (floatval($value['pay_price']) + floatval($value['send_price']));
- $list[$index]['content'] = '充值';
- } else {
- $list[$index]['flag'] = 1;
- $list[$index]['price'] = '-' . (floatval($value['pay_price']) + floatval($value['send_price']));
- $list[$index]['content'] = '扣除';
- }
- } elseif (in_array($value['order_type'], ['s_re'])) {
- $list[$index]['flag'] = 2;
- $list[$index]['price'] = '+' . (floatval($value['pay_price']) + floatval($value['send_price']));
- $list[$index]['content'] = "订单退款";
- } else {
- $list[$index]['flag'] = 1;
- $list[$index]['price'] = '-' . floatval($value['pay_price']);
- if ($value['order_type'] == 's') {
- $goods = Goods::find()->alias('g')->where([
- 'g.store_id' => $this->store_id
- ])->leftJoin(['od' => OrderDetail::tableName()],'od.goods_id=g.id')
- ->andWhere(['od.order_id' => $value['id']])->select(['g.name'])->asArray()->column();
- $goods_str = implode(',', $goods);
- $list[$index]['content'] = "消费-商城订单{$goods_str}";
- }
- }
- $list[$index]['date'] = date('Y-m-d H:i:s', $value['created_at']);
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $list,
- 'date' => $date
- ]
- ];
- }
- //充值记录
- public function rechargeOrder() {
- $query = ReOrder::find()->where([
- 'is_pay' => 1,
- 'is_delete' => 0,
- 'store_id' => $this->store_id,
- 'user_id' => $this->user->id,
- ])->orderBy('id DESC');
- $data = pagination_make($query);
- return [
- 'code' => 0,
- 'data' => $data,
- // 'sql' => $query->createCommand()->getRawSql(),
- ];
- }
- public function yifang()
- {
- if (!$this->validate()) {
- return $this->errorResponse;
- }
- //搜索置顶月份的充值记录及余额消费记录
- $date = $this->date;
- $start = strtotime($date);
- $end = strtotime(date('Y-m-t', $start)) + 86400;
- $start=date('Y-m-d',$start);
- $end=date('Y-m-d',$end);
- $list = Fyorder::find()->where(['user_id'=>$this->user->id,'type'=>1])->andWhere(['<', 'addtime', $end])->andWhere(['>=', 'addtime', $start])->orderBy('addtime desc')->asArray()->all();
- foreach ($list as $index => $value) {
- $list[$index]['flag'] = 0;
- $list[$index]['price'] = '+' . round(floatval($value['money']),2);
- $list[$index]['content'] = "优惠券释放";
- $list[$index]['date'] = $value['addtime'];
- }
- $yi = $list[0]['yifan'];
- if(!$yi){
- $yi=0;
- }
- return new ApiResponse(0,'success',[
- 'list' => $list,
- 'date' => $date,
- 'yi'=>$yi
- ]);
- }
- private function getSql2($user_id,$confirm_time,$store_id)
- {
- $s_table = Order::tableName();
- $ms_table = MsOrder::tableName();
- $pt_table = PtOrder::tableName();
- $yy_table = YyOrder::tableName();
- $order_share_table = OrderShare::tableName();
- $sql_s = "(
- SELECT
- 's' AS `order_type`,
- `id`,
- `order_no`,
- `is_pay`,
- `pay_price`,
- `is_price`,
- `user_id`,
- `apply_delete`,
- `addtime`,
- `parent_id` AS `parent_id_1`,
- `parent_id_1` AS `parent_id_2`,
- `parent_id_2` AS `parent_id_3`,
- `first_price`,
- `second_price`,
- `third_price`,
- `rebate`,
- `store_id`,
- `is_show`,
- `is_confirm`,
- `confirm_time`,
- `fyjine`,
- `fysingle`,
- `mch_fyjine`,
- `mch_fysingle`
- FROM
- {$s_table}
- WHERE
- (`is_pay` = 1)
- AND (`is_confirm` = 1)
- AND (`user_id` = {$user_id})
- AND (`is_delete` = 0)
- AND (`is_sale` = 1)
- AND (`confirm_time` <= {$confirm_time})
- AND (store_id = {$store_id})
- )";
- $sql_ms = "(
- SELECT
- 'ms' AS `order_type`,
- `id`,
- `order_no`,
- `is_pay`,
- `pay_price`,
- `is_price`,
- `user_id`,
- `apply_delete`,
- `addtime`,
- `parent_id` AS `parent_id_1`,
- `parent_id_1` AS `parent_id_2`,
- `parent_id_2` AS `parent_id_3`,
- `first_price`,
- `second_price`,
- `third_price`,
- `rebate`,
- `store_id`,
- `is_show`,
- `is_confirm`,
- `confirm_time`,
- `fyjine`,
- `fysingle`,
- `mch_fyjine`,
- `mch_fysingle`
- FROM
- {$ms_table}
- WHERE
- (`is_pay` = 1)
- AND (`is_confirm` = 1)
- AND (`user_id` = {$user_id})
- AND (`is_delete` = 0)
- AND (`is_sale` = 1)
- AND (`confirm_time` <= {$confirm_time})
- AND (store_id = {$store_id})
- )";
- $sql_pt = "(
- SELECT
- 'pt' AS `order_type`,
- `pt`.`id`,
- `pt`.`order_no`,
- `pt`.`is_pay`,
- `pt`.`pay_price`,
- `pt`.`is_price`,
- `pt`.`user_id`,
- `pt`.`apply_delete`,
- `pt`.addtime,
- `os`.`parent_id_1`,
- `os`.`parent_id_2`,
- `os`.`parent_id_3`,
- `os`.`first_price`,
- `os`.`second_price`,
- `os`.`third_price`,
- `os`.`rebate`,
- `pt`.`store_id`,
- `pt`.`is_show`,
- `pt`.`is_confirm`,
- `pt`.`confirm_time`,
- `pt`.`fyjine`,
- `pt`.`fysingle`,
- `pt`.`mch_fyjine`,
- `pt`.`mch_fysingle`
- FROM
- {$pt_table} `pt`
- LEFT JOIN {$order_share_table} `os` ON pt.id = os.order_id AND `os`.`type` = 0
- WHERE
- (`pt`.`is_pay` = 1)
- AND (`pt`.`is_confirm` = 1)
- AND (`pt`.`user_id` = {$user_id})
- AND (`pt`.`is_delete` = 0)
- AND (`pt`.`confirm_time` <= {$confirm_time})
- AND (pt.store_id = {$store_id})
- )";
- $sql_yy = "(
- SELECT
- 'yy' AS `order_type`,
- `yy`.`id`,
- `yy`.`order_no`,
- `yy`.`is_pay`,
- `yy`.`pay_price`,
- `yy`.`is_use` is_price,
- `yy`.`user_id`,
- `yy`.`apply_delete`,
- `yy`.addtime,
- `os`.`parent_id_1`,
- `os`.`parent_id_2`,
- `os`.`parent_id_3`,
- `os`.`first_price`,
- `os`.`second_price`,
- `os`.`third_price`,
- `os`.`rebate`,
- `yy`.`store_id`,
- `yy`.`is_show`,
- `yy`.`is_use`,
- `yy`.`use_time`,
- `yy`.`fyjine`,
- `yy`.`fysingle`,
- `yy`.`mch_fyjine`,
- `yy`.`mch_fysingle`
- FROM
- {$yy_table} `yy`
- LEFT JOIN {$order_share_table} `os` ON os.order_id = yy.id AND `os`.`type` = 1
- WHERE
- (`yy`.`is_pay` = 1)
- AND (`yy`.`is_use` = 1)
- AND (`yy`.`is_delete` = 0)
- AND (`yy`.`user_id` = {$user_id})
- AND (`yy`.`use_time` <= {$confirm_time})
- AND (yy.store_id = {$store_id})
- )";
- $sql = " FROM (
- SELECT * FROM ( {$sql_s} UNION {$sql_ms} UNION {$sql_pt} UNION {$sql_yy} ) AS `l`
- WHERE
- `l`.`store_id` = 1
- ) AS `al` ";
- return $sql;
- }
- public function daifang()
- {
- if (!$this->validate()) {
- return $this->errorResponse;
- }
- $store=Store::findOne(['id'=>$this->store_id]);
- $now=time();
- //计算自动确认收货
- $com=(3600*24)*$store->after_sale_time;
- //是否超过售后期
- $confirm_time=$now-$com;
- $xfybl=round(($store->xfybl)/1000,2);//消费购物返佣比例
- $sfybl=round(($store->sfybl)/1000,2);//商家返佣比例
- //查询客户返佣订单
- $select = "SELECT al.*";
- $sql = $this->getSql2($this->user->id,$confirm_time,$this->store_id);
- $list = \Yii::$app->db->createCommand($select . $sql . "ORDER BY al.created_at DESC")->queryAll();
- $payjine=0;
- foreach($list as $v){
- $payjine += $v['pay_price'];
- }
- //作为客户订单返佣金额
- $oprice=round($payjine,2);
- //购买加速金额
- $ljine=LevelOrder::find()->where(['is_pay'=>1,'user_id'=>$this->user->id])->SUM('pay_price');
- //若用户为商户
- $mch_id=Mch::find()->where(['user_id'=>$this->user->id])->select('id')->asArray()->all();
- $mjine=0;
- if($mch_id){
- //查询商户订单
- $str=array();
- foreach($mch_id as $v){
- $str[]=$v['id'];
- }
- $owhere=array();
- $owhere['is_pay']=1;
- $owhere['is_confirm']=1;
- $owhere['confirm_time']<=$confirm_time;
- $mjine=Order::find()->where($owhere)->andWhere(['in','mch_id',$str])->SUM('pay_price');
- $mjine=round($mjine,2);
- }
- $allprice=round(($oprice*$xfybl)+$ljine,2);
- $mjine=round($mjine*$sfybl,2);
- //全返金额
- $allprice=$allprice+$mjine;
- if (!$allprice) {
- $allprice=0;
- }
- //全返金额$order->pay_price-$order->express_price;
- $yifan=Fyorder::find()->where(['user_id'=>$this->user->id])->select('yifan,zonge')->limit(1)->orderBy('addtime desc')->all();
- //$zonge=round($yifan[0]->zonge,2);
- $yifan=round($yifan[0]->yifan,2);
- if(!$yifan){
- $yifan=0;
- }
- //$allprice=$zonge-$yifan;
- $allprice=$allprice-$yifan;
- //搜索置顶月份的充值记录及余额消费记录
- $date = $this->date;
- $start = strtotime($date);
- $end = strtotime(date('Y-m-t', $start)) + 86400;
- $end = strtotime(date('Y-m-t', $start)) + 86400;
- $start=date('Y-m-d',$start);
- $end=date('Y-m-d',$end);
- $list = Fyorder::find()->where(['user_id'=>$this->user->id])->andWhere(['<', 'addtime', $end])->andWhere(['>=', 'addtime', $start])->orderBy('addtime desc')->asArray()->all();
- foreach ($list as $index => $value) {
- if($value['type']==1){
- $list[$index]['flag'] = 1;
- $list[$index]['price'] = '-' . round(floatval($value['money']),2);
- $list[$index]['daifan'] = $value['zonge']-$value['yifan'];
- $list[$index]['content'] = "优惠券释放";
- $list[$index]['date'] = $value['addtime'];
- }elseif($value['type']==2){
- $list[$index]['flag'] = 0;
- $list[$index]['price'] = '+' . round(floatval($value['money']),2);
- $list[$index]['daifan'] = $value['zonge']-$value['yifan'];
- $list[$index]['content'] = "优惠券释放";
- $list[$index]['date'] = $value['addtime'];
- }
- }
- return new ApiResponse(0,'success',[
- 'list' => $list,
- 'date' => $date,
- 'dai'=>$allprice
- ]);
- }
- public function getSql()
- {
- // $r_table = ReOrder::tableName();
- $s_table = Order::tableName();
- // $ms_table = MsOrder::tableName();
- // $pt_table = PtOrder::tableName();
- // $yy_table = YyOrder::tableName();
- $s_refund_table = OrderRefund::tableName();
- // $ms_refund_table = MsOrderRefund::tableName();
- // $pt_refund_table = PtOrderRefund::tableName();
- // $yy_refund_table = YyOrder::tableName();
- // $pondTable = PondLog::tableName();
- // $scratchTable = ScratchLog::tableName();
- $logTable = AccountLog::tableName();
- // $query_r = "(
- // SELECT
- // 'r' AS order_type,
- // id,
- // created_at,
- // pay_price,
- // pay_type,
- // send_price,
- // '' AS content
- // FROM {$r_table}
- // WHERE store_id = {$this->store_id}
- // AND user_id = {$this->user->id}
- // AND is_delete = 0
- // AND is_pay = 1
- // )";
- $query_s = "(
- SELECT
- 's' AS order_type,
- id,
- created_at,
- pay_price,
- 0 AS pay_type,
- 0 AS send_price,
- '' AS content
- FROM {$s_table}
- WHERE store_id = {$this->store_id}
- AND user_id = {$this->user->id}
- AND is_delete = 0
- AND trade_status != 1
- AND is_pay = 1
- AND pay_type = 3
- AND is_show = 1
- )";
- // $query_ms = "(
- // SELECT
- // 'ms' AS order_type,
- // id,
- // created_at,
- // pay_price,
- // 0 AS pay_type,
- // 0 AS send_price,
- // '' AS content
- // FROM {$ms_table}
- // WHERE store_id = {$this->store_id}
- // AND user_id = {$this->user->id}
- // AND is_delete = 0
- // AND is_cancel = 0
- // AND is_pay = 1
- // AND pay_type = 3
- // AND is_show = 1
- // )";
- // $query_pt = "(
- // SELECT
- // 'pt' AS order_type,
- // id,
- // created_at,
- // pay_price,
- // 0 AS pay_type,
- // 0 AS send_price,
- // '' AS content
- // FROM {$pt_table}
- // WHERE store_id = {$this->store_id}
- // AND user_id = {$this->user->id}
- // AND is_delete = 0
- // AND is_cancel = 0
- // AND is_pay = 1
- // AND pay_type = 3
- // AND is_show = 1
- // )";
- //
- // $query_yy = "(
- // SELECT
- // 'yy' AS order_type,
- // id,
- // created_at,
- // pay_price,
- // 0 AS pay_type,
- // 0 AS send_price,
- // '' AS content
- // FROM {$yy_table}
- // WHERE store_id = {$this->store_id}
- // AND user_id = {$this->user->id}
- // AND is_delete = 0
- // AND is_cancel = 0
- // AND is_pay = 1
- // AND pay_type = 2
- // AND is_show = 1
- // )";
- $query_s_re = "(
- SELECT
- 's_re' AS order_type,
- ore.id,
- ore.created_at,
- ore.refund_price AS pay_price,
- 0 AS pay_type,
- 0 AS send_price,
- '' AS content
- FROM {$s_refund_table} AS ore
- LEFT JOIN {$s_table} AS o ON o.id = ore.order_id
- WHERE ore.store_id = {$this->store_id}
- AND ore.is_delete = 0
- AND ore.type = 1
- AND ore.status = 1
- AND o.pay_type = 3
- AND ore.user_id = {$this->user->id}
- AND o.is_show = 1
- )";
- // $query_ms_re = "(
- // SELECT
- // 'ms_re' AS order_type,
- // ore.id,
- // ore.created_at,
- // ore.refund_price AS pay_price,
- // 0 AS pay_type,
- // 0 AS send_price,
- // '' AS content
- // FROM {$ms_refund_table} AS ore
- // LEFT JOIN {$ms_table} AS o ON o.id = ore.order_id
- // WHERE ore.store_id = {$this->store_id}
- // AND ore.is_delete = 0
- // AND ore.type = 1
- // AND ore.status = 1
- // AND o.pay_type = 3
- // AND ore.user_id = {$this->user->id}
- // AND o.is_show = 1
- // )";
- //
- // $query_pt_re = "(
- // SELECT
- // 'pt_re' AS order_type,
- // ore.id,
- // ore.created_at,
- // ore.refund_price AS pay_price,
- // 0 AS pay_type,
- // 0 AS send_price,
- // '' AS content
- // FROM {$pt_refund_table} AS ore
- // LEFT JOIN {$pt_table} AS o ON o.id = ore.order_id
- // WHERE ore.store_id = {$this->store_id}
- // AND ore.is_delete = 0
- // AND ore.type = 1
- // AND ore.status = 1
- // AND o.pay_type = 3
- // AND ore.user_id = {$this->user->id}
- // AND o.is_show = 1
- // )";
- //
- // $query_yy_re = "(
- // SELECT
- // 'yy_re' AS order_type,
- // ore.id,
- // ore.refund_time AS addtime,
- // ore.pay_price,
- // 0 AS pay_type,
- // 0 AS send_price,
- // '' AS content
- // FROM {$yy_refund_table} AS ore
- // WHERE ore.store_id = {$this->store_id}
- // AND ore.user_id = {$this->user->id}
- // AND ore.is_pay = 1
- // AND ore.is_delete = 0
- // AND ore.pay_type = 2
- // AND ore.is_cancel = 0
- // AND ore.is_refund = 1
- // AND ore.is_show = 1
- // )";
- $query_log = "(
- SELECT
- 'log' AS order_type,
- lt.id,
- lt.created_at,
- lt.amount AS pay_price,
- 0 AS pay_type,
- 0 AS send_price,
- lt.desc AS content
- FROM {$logTable} AS lt
- WHERE lt.store_id = {$this->store_id}
- AND lt.type = 2
- AND lt.order_type = 0
- AND lt.user_id = {$this->user->id}
- )";
- // $pondLog = "(
- // SELECT
- // 'pond' AS order_type,
- // p.id,
- // p.created_at as addtime,
- // p.price AS pay_price,
- // 0 AS pay_type,
- // 0 AS send_price,
- // '' AS content
- // FROM {$pondTable} AS p
- // WHERE p.store_id = {$this->store_id}
- // AND p.type = 1
- // AND p.status = 1
- // AND p.user_id = {$this->user->id}
- // )";
- //
- // $scratchLog = "(
- // SELECT
- // 'scratch' AS order_type,
- // id,
- // create_time as addtime,
- // price AS pay_price,
- // 0 AS pay_type,
- // 0 AS send_price,
- // '' AS content
- // FROM {$scratchTable}
- // WHERE store_id = {$this->store_id}
- // AND type = 1
- // AND status = 2
- // AND user_id = {$this->user->id}
- // )";
- // $sql = " FROM (
- // {$query_r}
- // UNION {$query_s}
- // UNION {$query_ms}
- // UNION {$query_pt}
- // UNION {$query_yy}
- // UNION {$query_s_re}
- // UNION {$query_ms_re}
- // UNION {$query_pt_re}
- // UNION {$query_yy_re}
- // UNION {$query_log}
- // UNION {$pondLog}
- // UNION {$scratchLog}
- // ) AS al ";
- $sql = " FROM (
- {$query_s}
- UNION {$query_s_re}
- UNION {$query_log}
- ) AS al ";
- return $sql;
- }
- }
|