ItgOrderModel.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * ItgOrderModel.php UTF-8
  4. * 积分订单
  5. *
  6. * @date : 2018/5/7 22:03
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\shop;
  13. use huo\model\common\CommonModel;
  14. use huolib\constant\MemItgConst;
  15. class ItgOrderModel extends CommonModel {
  16. protected $name = 'itg_order';
  17. // 开启自动写入时间戳字段
  18. protected $autoWriteTimestamp = true;
  19. /**
  20. * 关联商品
  21. *
  22. * @return ItgOrderModel|\think\model\relation\BelongsTo
  23. */
  24. public function goods() {
  25. return $this->hasOne('huo\model\shop\GoodsModel', 'id', 'goods_id', 'goods')->field(
  26. ['id', 'goods_name', 'object_type', 'is_real', 'original_img']
  27. );
  28. }
  29. /**
  30. * @return \think\model\relation\HasOne
  31. */
  32. public function mem() {
  33. return $this->hasOne('huo\model\member\MemberModel', 'id', 'mem_id', 'mem')->field(
  34. ['id', 'username', 'nickname', 'avatar', 'mobile']
  35. );
  36. }
  37. /**
  38. * @return \think\model\relation\HasOne
  39. */
  40. public function memMobile() {
  41. return $this->hasOne('huo\model\member\MemberModel', 'id', 'mem_id', 'mem')->field(['id', 'mobile'])
  42. ->setEagerlyType(0);
  43. }
  44. /**
  45. * 创建订单
  46. *
  47. * @param array $data
  48. *
  49. * @return bool|array
  50. */
  51. public function createOrder($data) {
  52. $_data['order_id'] = get_val($data, 'order_id', '');
  53. $_data['mem_id'] = get_val($data, 'mem_id', 0);
  54. $_data['flag'] = get_val($data, 'flag', MemItgConst::SHOP_FLAG_UNKNOWN);
  55. $_data['act_id'] = get_val($data, 'act_id', MemItgConst::SHOP_FLAG_UNKNOWN);
  56. $_data['goods_id'] = get_val($data, 'goods_id', 0);
  57. $_data['integral'] = get_val($data, 'integral', 0.00);
  58. $_data['status'] = get_val($data, 'status', MemItgConst::PAY_STATUS_NOT);
  59. $_data['shipping_status'] = get_val($data, 'shipping_status', MemItgConst::SHIP_STATUS_NOT);
  60. $_data['consignee'] = get_val($data, 'consignee', '');
  61. $_data['country'] = get_val($data, 'country', 0);
  62. $_data['province'] = get_val($data, 'province', 0);
  63. $_data['city'] = get_val($data, 'city', 0);
  64. $_data['district'] = get_val($data, 'district', 0);
  65. $_data['town'] = get_val($data, 'town', 0);
  66. $_data['address'] = get_val($data, 'address', '');
  67. $_data['zipcode'] = get_val($data, 'zipcode', '');
  68. $_data['mobile'] = get_val($data, 'mobile', '');
  69. $_data['email'] = get_val($data, 'email', '');
  70. $_data['shipping_code'] = get_val($data, 'shipping_code', '');
  71. $_data['shipping_name'] = get_val($data, 'shipping_name', '');
  72. $_data['shipping_price'] = get_val($data, 'shipping_price', 0.00);
  73. $_data['invoice_no'] = get_val($data, 'invoice_no', '');
  74. $_data['user_note'] = get_val($data, 'user_note', '');
  75. $_data['admin_note'] = get_val($data, 'admin_note', '');
  76. $_data['shipping_time'] = get_val($data, 'shipping_time', 0);
  77. $_data['confirm_time'] = get_val($data, 'confirm_time', 0);
  78. if ($_obj = self::create($_data, true)) {
  79. $_data['id'] = $_obj->id;
  80. return $_data['id'];
  81. } else {
  82. return false;
  83. }
  84. }
  85. /**
  86. * 更新订单
  87. *
  88. * @param array $order_data
  89. * @param string $io_id
  90. *
  91. * @return bool
  92. */
  93. public function updateOrder($order_data, $io_id) {
  94. $_map['id'] = $io_id;
  95. $_data = $order_data;
  96. $_rs = self::update($_data, $_map, true);
  97. if (false == $_rs) {
  98. return false;
  99. } else {
  100. return true;
  101. }
  102. }
  103. /**
  104. * 获取订单状态
  105. *
  106. * @param $order_id
  107. *
  108. * @return bool
  109. * @throws \think\db\exception\DataNotFoundException
  110. * @throws \think\db\exception\ModelNotFoundException
  111. * @throws \think\exception\DbException
  112. */
  113. public function getStatus($order_id) {
  114. $_map['order_id'] = $order_id;
  115. $_status = self::where($_map)->field('status, shipping_status')->find();
  116. if (false == $_status) {
  117. return false;
  118. }
  119. $_rdata['status'] = $_status['status'];
  120. $_rdata['shipping_status'] = $_status['shipping_status'];
  121. return $_rdata;
  122. }
  123. /**
  124. * 获取订单详情
  125. *
  126. * @param $order_id
  127. *
  128. * @return array|bool|false
  129. * @throws \think\Exception
  130. * @throws \think\db\exception\DataNotFoundException
  131. * @throws \think\db\exception\ModelNotFoundException
  132. * @throws \think\exception\DbException
  133. */
  134. public function getDetail($order_id) {
  135. $_map['order_id'] = $order_id;
  136. $_data = self::with('goods')->where($_map)->find();
  137. if (false == $_data) {
  138. return false;
  139. }
  140. if (is_object($_data)) {
  141. $_data = $_data->toArray();
  142. }
  143. return $_data;
  144. }
  145. /**
  146. * 获取订单列表
  147. *
  148. * @param $_map
  149. * @param $_order
  150. * @param $_offset
  151. *
  152. * @return \think\Paginator
  153. * @throws \think\exception\DbException
  154. */
  155. public function getList($_map, $_order, $_offset) {
  156. $_field = 'id, order_id, mem_id, flag, goods_id, integral, status, shipping_status';
  157. $_item = self::with('goods')
  158. ->with('mem')
  159. ->field($_field)->where($_map)->order($_order)->paginate($_offset);
  160. return $_item;
  161. }
  162. }