123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- namespace app\api\controller\shop;
- use app\common\controller\Api;
- use app\common\model\HotelModel;
- use app\common\model\OfflineShopModel;
- use app\common\model\OfflineTypeModel;
- use app\utils\DataUtil;
- use think\Db;
- /**
- * 示例接口
- */
- class ShopHotel extends Api
- {
- protected $noNeedLogin = [''];
- protected $noNeedRight = ['*'];
- public function home()
- {
- $user_id = $this->auth->id;
- $model = new HotelModel();
- $info = $model->getDetail(
- params: ['user_id' => $user_id],
- select: ['id','invite_id','user_id','name','image','images','back_rate','address']
- );
- if (!$info){
- return $this->error('未开通门店');
- }
- // 待核销金额
- $wait_use = Db::name('bill')->where(['shop_id'=>$info['id'],'table_name'=>'hotel_order','status'=>2])->field('sum(total_amount - back_amount) as money')->find();
- // 已核销
- $used = Db::name('bill')->where(['shop_id'=>$info['id'],'table_name'=>'hotel_order','status'=>3])->field('sum(total_amount - back_amount) as money')->find();
- // 已退款
- $refund = Db::name('bill')->where(['shop_id'=>$info['id'],'table_name'=>'hotel_order','status'=>4])->field('sum(total_amount - back_amount) as money')->find();
- $statistics = [
- 'wait_use' => $wait_use['money'] ?? 0,
- 'used' => $used['money'] ?? 0,
- 'refund' => $refund['money'] ?? 0,
- ];
- return $this->success('success',[
- 'info' => $info,
- 'statistics' => $statistics
- ]);
- }
- // 交易统计
- public function statistics()
- {
- $params = $this->request->param();
- $user_id = $this->auth->id;
- if (empty($params['type'])){
- $params['type'] = 1;
- }
- $model = new HotelModel();
- $info = $model->getDetail(
- params: ['user_id' => $user_id],
- select: ['id','invite_id','user_id','name','image','images','back_rate','address']
- );
- if (!$info){
- return $this->error('未开通门店');
- }
- switch ($params['type']){
- case 1:
- // 今天
- $createtimeBetween = [
- strtotime(date('Y-m-d 00:00:00')),
- strtotime(date('Y-m-d 23:59:59')),
- ];
- break;
- case 2:
- // 昨天
- $createtimeBetween = [
- strtotime(date('Y-m-d 00:00:00', strtotime('-1 day'))),
- strtotime(date('Y-m-d 23:59:59', strtotime('-1 day'))),
- ];
- break;
- case 3:
- // 本月
- $createtimeBetween = [
- strtotime(date('Y-m-01 00:00:00')),
- strtotime(date('Y-m-d 23:59:59')),
- ];
- break;
- default:
- $createtimeBetween = [
- strtotime(date('Y-m-d 00:00:00'),strtotime($params['date'])),
- strtotime(date('Y-m-d 23:59:59'),strtotime($params['date'])),
- ];
- break;
- }
- $wait_use = Db::name('bill')
- ->where(['shop_id'=>$info['id'],'table_name'=>'hotel_order'])
- ->whereIn('status',[1,2,3])
- ->whereBetween('createtime',$createtimeBetween)
- ->field('sum(total_amount - back_amount) as money,count(id) as num')
- ->find();
- return $this->success('success',[
- 'money' => $wait_use['money'] ?? 0,
- 'num' => $used['num'] ?? 0,
- ]);
- }
- // 趋势图
- public function trend()
- {
- $user_id = $this->auth->id;
- $model = new HotelModel();
- $info = $model->getDetail(
- params: ['user_id' => $user_id],
- select: ['id','invite_id','user_id','name','image','images','back_rate','address']
- );
- if (!$info){
- return $this->error('未开通门店');
- }
- // 七日数据走势统计
- $createtimeBetween = [
- strtotime(date('Y-m-d 00:00:00', strtotime('-6 day'))),
- strtotime(date('Y-m-d 23:59:59')),
- ];
- $dates = [];
- for ($i = 6; $i >= 0; $i--){
- $dates[] = date('Y-m-d', strtotime('-'.$i.' day'));
- }
- $wait_use = Db::name('bill')
- ->field('DATE(FROM_UNIXTIME(createtime)) as order_date,sum(total_amount - back_amount) as money,count(id) as num')
- ->where(['shop_id'=>$info['id'],'table_name'=>'hotel_order'])
- ->whereIn('status',[1,2,3])
- ->whereBetween('createtime',$createtimeBetween)
- ->group('order_date')
- ->order('order_date','asc')
- ->select();
- $num = [];
- $money = [];
- foreach ($dates as $key=>$date){
- $num[$key] = 0;
- $money[$key] = '0';
- foreach ($wait_use as $k=>$v){
- if ($date == $v['order_date']){
- $num[$key] = $v['num'];
- $money[$key] = $v['money'];
- }
- }
- $dates[$key] = date('m/d',strtotime($date));
- }
- return $this->success('success',[
- 'money' => $money,
- 'num' => $num,
- 'dates' => $dates
- ]);
- }
- }
|