GreenOrder.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 订单数据
  7. */
  8. namespace app\green\model;
  9. use think\Model;
  10. class GreenOrder extends Model{
  11. //所属商品
  12. public function shop(){
  13. return $this->hasOne('GreenShop','shop_id','id');
  14. }
  15. /**
  16. * @param $data
  17. * @param $order_no
  18. * 购买商品生成订单数据
  19. */
  20. public static function insertOrder($param,$order_no){
  21. $order = [
  22. 'shop_id' => $param['shop_id'],
  23. 'member_miniapp_id' => $param['member_miniapp_id'],
  24. 'message' => $param['message'],
  25. 'user_id' => $param['user_id'],
  26. 'order_no' => $order_no,
  27. 'points' => $param['points'],
  28. 'shop_cache' => $param['shop_cache'],
  29. 'express_name' => $param['express_name'],
  30. 'express_phone' => $param['express_phone'],
  31. 'express_address' => $param['express_address'],
  32. 'status' => 0,
  33. 'is_del' => 0,
  34. 'paid_at' => 0,
  35. 'create_time' => time()
  36. ];
  37. return self::create($order);
  38. }
  39. /**
  40. * 获取订单数据(单个订单预览)
  41. * 使用:前台查询用户自己的订单
  42. * @param string $order_no 订单ID
  43. * @param integer $user_id 要获取的订单用户
  44. * @param integer $type 要获取的订单状态
  45. * @return array
  46. */
  47. public static function getOrder(string $order_no,int $user_id = 0,int $is_del = 1){
  48. if($user_id){
  49. $condition['user_id'] = $user_id;
  50. }
  51. if($is_del){
  52. $condition['is_del'] = 0;
  53. }
  54. $condition['order_no'] = $order_no;
  55. return self::where($condition)->order('id desc')->select();
  56. }
  57. }