123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <?php
- namespace app\common\model;
- use app\common\service\helperService;
- use think\Db;
- /**
- * 订单管理表
- * Class GoodsTypeModel
- * @package app\common\model
- */
- class OrderModel extends BaseModel
- {
- protected $table = 'order';
- /**
- * 获得用户购买商品数量
- * @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_no')
- ->join('order_list ol','ol.order_no = order.order_no','LEFT')
- ->where($condition)
- ->select();
- }
- /**
- * 获取总条数据信息
- * @param array $condition
- * @return array|false|\PDOStatement|string|Model
- */
- public function getCounts($condition=[]){
- if($condition){
- return $this->alias('order')->where($condition)->join('order_sales os','os.order_no = order.order_no','LEFT')->count();
- }
- return $this->count();
- }
- /**
- * 获得订单详情
- * @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.actual_price,ol.number as ol_num,product.images,product.product_id,dg.price as dg_price,promo.price as promo_price,product_type.type_name,logistics_basic.e_name,logistics_basic.logistics_name')
- ->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')
- ->join('logistics_basic logistics_basic','logistics_basic.logistics_id=order.logistics_id','LEFT')
- ->join('product_type product_type','product.type_id = product_type.type_id and product_type.status=1','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]])->column('*');
- foreach ($orderInfo as $order){
- $productInfo = Db::table('product')->where(['product_no'=>"{$order['product_no']}"])->find();
- $productInfo = helperService::modelDataToArr($productInfo);
- if(empty($productInfo)){
- continue;
- }
- $number = intval($order['number']) + intval($productInfo['number']);
- $sales_volume = intval($productInfo['sales_volume']) - intval($order['number']);
- Db::table('order')->startTrans();
- Db::table('product')->where(['product_no'=>"{$order['product_no']}",'sales_volume'=>"{$productInfo['sales_volume']}"])->update(['number'=>"{$number}",'sales_volume'=>"{$sales_volume}"]);
- $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();
- }
- }
- //后台订单分页
- public function getOrderPage($page,$pageSize,$condition=[],$is_count = false,$order=''){
- $join=[
- ['user user','user.user_no=order.user_no','LEFT'],
- ];
- $this->alias('order')
- ->field('order.*,user.user_name,user.mobile')
- ->join($join);
- if($condition){
- $this->where($condition);
- }
- if($is_count){
- return $this->count();
- }
- if($order){
- $this->order($order);
- }
- return $this->page($page,$pageSize)->select();
- }
- //获取订单单个信息
- public function getOrderOne($condition=[]){
- $join=[
- ['user user','user.user_no=order.user_no','LEFT'],
- ];
- $this->alias('order')
- ->field('order.*,user.user_name,user.mobile,user.gender,user.total_score,user.usable_score')
- ->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 array $condition
- * @return false|\PDOStatement|string|\think\Collection
- */
- public function getOrderAndSales($condition=[]){
- return $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.is_shows,os.add_ts as sa_add_ts,logistics_basic.e_name')
- ->join('order_sales os','os.order_no = order.order_no','LEFT')
- ->join('logistics_basic logistics_basic','logistics_basic.logistics_id=order.logistics_id','LEFT')
- ->order('order_status asc,os.status desc')
- ->where($condition)
- ->select();
- }
- /**
- *@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();
- }
- }
|