'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; } }