123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- <?php
- namespace app\common\model;
- use think\Db;
- /**
- * 订单管理表
- * Class GoodsTypeModel
- * @package app\common\model
- */
- class OrderModel extends BaseModel
- {
- protected $table = 'order';
- /**
- * 获取状态名称
- */
- public function getOrderStatusText($data)
- {
- $arr= [10=>'未付款','11'=>'关闭订单',20=>'待发货',30=>'已发货',31=>'已收货',40=>'退款成功'];
- return $arr[$data['order_status']];
- }
- //后台订单分页
- public function getOrderPage($page,$pageSize,$condition=[],$is_count = false,$order=''){
- $join=[
- ['user user','user.user_no=order.user_no','LEFT'],
- ['pay_list pay_list','pay_list.order_no=order.order_no','LEFT'],
- ['logistics_basic logistics_basic','logistics_basic.logistics_id=order.logistics_id','LEFT'],
- ];
- $this->alias('order')
- ->field('order.*,user.user_name,user.mobile,user.real_name,user.user_name,
- pay_list.wx_price,logistics_basic.logistics_name,pay_list.pay_no,pay_list.add_ts add_payTime')
- ->join($join);
- if($condition){
- $this->where($condition);
- }
- if($is_count){
- return $this->group('pay_list.order_no')->count();
- }
- if($order){
- $this->order($order);
- }
- return $this->page($page,$pageSize)->group('pay_list.order_no')->select();
- }
- //后台订单分页
- public function getOrderLockPage($page,$pageSize,$condition=[],$is_count = false,$order=''){
- $join=[
- ['user user','user.user_no=order.user_no','LEFT'],
- ['pay_list pay_list','pay_list.order_no=order.order_no','LEFT'],
- ['order_sales order_sales','order_sales.order_no=order.order_no','LEFT'],
- ];
- $this->alias('order')
- ->field('order.*,user.user_name,user.real_name,user.mobile,pay_list.wx_price,pay_list.pay_no,
- order_sales.mobile sales_mobile,sales_price,sales_type,sales_userNote,sales_adminNote,
- order_sales.sales_id,order_sales.status sales_status,order_sales.add_ts sales_add_ts
- ')
- ->join($join);
- if($condition){
- $this->where($condition);
- }
- if($is_count){
- return $this->group('pay_list.order_no')->count();
- }
- if($order){
- $this->order($order);
- }
- return $this->page($page,$pageSize)->group('pay_list.order_no')->select();
- }
- //获取订单单个信息
- public function getOrderOne($condition=[]){
- $join=[
- ['user user','user.user_no=order.user_no','LEFT'],
- ['logistics_basic com','com.logistics_id=order.logistics_id','LEFT'],
- ['pay_list pay_list','pay_list.order_no=order.order_no','LEFT'],
- ];
- $this->alias('order')
- ->field('order.*,user.user_name,user.mobile,user.gender,user.total_score,user.usable_score,user.real_name,user.lable,
- com.logistics_name,com.e_name,pay_list.pay_no
- ')
- ->join($join);
- if($condition){
- $this->where($condition);
- }
- return $this->find();
- }
- //获取物流信息
- public function getLogisticsInfo($condition=[]){
- $join=[
- ['logistics_basic logistics_basic','logistics_basic.logistics_id=order.logistics_id','LEFT'],
- ];
- if($condition){
- $this->where($condition);
- }
- $this->alias('order')
- ->field('order.*,logistics_basic.logistics_name')
- ->join($join);
- return $this->find();
- }
- /**
- * 获得用户购买商品数量
- * @param $condition
- * @return false|\PDOStatement|string|\think\Collection
- */
- public function getProduct($condition){
- return $this->alias('order')
- ->field('order.order_id,order.order_no,ol.number,ol.product_id')
- ->join('order_list ol','ol.order_no = order.order_no','LEFT')
- ->where($condition)
- ->select();
- }
- /**
- * 获得订单详情
- * @param $condition
- * @return false|\PDOStatement|string|\think\Collection
- */
- // public function getOrderAndProduct($condition){
- // return $this->alias('order')
- // ->field('order.*,ol.number,ol.product_no,ol.product_price as ol_price,ol.number as ol_num,product.product_name,product.images,product.product_id')
- // ->join('order_list ol','ol.order_no = order.order_no','LEFT')
- // ->join('product product','product.product_no = ol.product_no','LEFT')
- // ->where($condition)
- // ->select();
- // }
- /**
- * 获得商品
- * @param $condition
- * @return false|\PDOStatement|string|\think\Collection
- */
- public function getOrderAndProduct($condition = []){
- $list = $this->alias('order')
- ->field('order.*,product.product_name,product.market_price,product.member_price,ol.number as ol_num,product.images,product.product_id,dg.price as dg_price,promo.price as promo_price')
- ->join('order_list ol','ol.order_no = order.order_no','LEFT')
- ->join('product product','product.product_no=ol.product_no','left')
- ->join('doctor_guide dg','dg.doctor_no = ol.doctor_no and dg.product_no = ol.product_no','LEFT')
- ->join('product_promo promo','promo.product_no = ol.product_no','LEFT')
- ->where($condition)
- ->select();
- foreach ($list as &$pro){
- if($pro['dg_price'] != null){
- $member_price = $pro['dg_price'];
- }elseif($pro['promo_price'] != null){
- $member_price = $pro['promo_price'];
- }else{
- $member_price = $pro['member_price'];
- }
- $intPrice = intval($member_price/100);
- $dotPrice = intval($member_price%100);
- $dotPrice = str_pad($dotPrice,2,0);
- $pro['sales_price'] = $intPrice.".".$dotPrice;
- }
- return $list;
- }
- /**
- * 检查半小时未付款的订单
- */
- public static function checkOrder(){
- $start = time()-30*60;
- $orderInfo = Db::table('order')->alias('order')
- ->field('order.order_id,order.order_no,ol.number,ol.product_no')
- ->join('order_list ol','ol.order_no = order.order_no','LEFT')
- ->where(['order_status'=>'10','add_time'=>['lt',$start]])->select();
- foreach ($orderInfo as $order){
- $productInfo = Db::table('product')->where(['product_no'=>"{$order['product_no']}"])->find();
- if(empty($productInfo)){
- continue;
- }
- $number = intval($order['number']) + intval($productInfo['number']);
- Db::table('order')->startTrans();
- Db::table('product')->where(['product_no'=>"{$order['product_no']}",'number'=>"{$productInfo['number']}"])->update(['number'=>"{$number}"]);
- $res = Db::table('order')->where(['order_id'=>"{$order['order_id']}",'order_status'=>10])->update(['order_status'=>11]);
- if($res === false){
- Db::table('order')->rollback();
- continue;
- }
- Db::table('order')->commit();
- }
- }
- /**
- * 得到订单表和售后表数据
- * @param array $condition
- * @return false|\PDOStatement|string|\think\Collection
- */
- public function getOrderAndSales($condition=[]){
- $this->alias('order')
- ->field('order.*,os.mobile as sa_mobile,os.sales_price,os.sales_type,os.sales_userNote,os.sales_adminNote,os.status as sa_status,os.add_ts as sa_add_ts')
- ->join('order_sales os','os.order_no = order.order_no','LEFT')
- ->order('order_status desc,os.status desc')
- ->where($condition)
- ->select();
- echo $this->getLastSql();exit;
- }
- /**
- *@param array 查询条件
- *@return array 查询结果
- *获取用户订单个状态数量
- */
- public function getUserOrderNums($where){
- $this->field("count(order_no) as nums,order_status");
- $this->where($where);
- $this->group('order_status');
- return $this->select();
- }
- //获取订单列表表格导出
- public function getOrderList($condition=[],$order=''){
- $join=[
- ['user user','user.user_no=order.user_no','LEFT'],
- ['pay_list pay','pay.order_no=order.order_no','LEFT'],
- ];
- $this->alias('order')
- ->field('order.*,order.address order_address,
- user.user_name,user.real_name,
- pay.wx_price,pay.pay_style,pay.add_ts pay_time,pay.pay_no
- ')
- ->join($join);
- if($condition){
- $this->where($condition);
- }
- if($order){
- $this->order($order);
- }
- return $this->BaseModel($this->select());
- }
- }
|