PayAppleModel.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * PayAppleModel.php UTF-8
  4. * 苹果支付记录表
  5. *
  6. * @date : 2018/6/11 15:37
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\order;
  13. use huo\model\common\CommonModel;
  14. use huo\model\member\MemberModel;
  15. use huolib\constant\CommonConst;
  16. class PayAppleModel extends CommonModel {
  17. protected $name = 'pay_apple';
  18. // 开启自动写入时间戳字段
  19. protected $autoWriteTimestamp = true;
  20. public function mem() {
  21. return $this->belongsTo(MemberModel::className(), 'mem_id', 'id');
  22. }
  23. public function pay() {
  24. return $this->belongsTo(OrderModel::className(), 'order_id', 'order_id');
  25. }
  26. /**
  27. * @param array $data
  28. *
  29. * @return bool|array
  30. */
  31. public function addData($data) {
  32. $_data['order_id'] = get_val($data, 'order_id', '');
  33. $_data['mem_id'] = get_val($data, 'mem_id', 0);
  34. $_data['mg_mem_id'] = get_val($data, 'mg_mem_id', 0);
  35. $_data['apple_id'] = get_val($data, 'apple_id', '');
  36. $_data['product_id'] = get_val($data, 'product_id', '');
  37. $_data['idfv'] = get_val($data, 'idfv', '');
  38. $_data['idfa'] = get_val($data, 'idfa', '');
  39. if ($_obj = self::create($_data, true)) {
  40. $_data['id'] = $_obj->id;
  41. return $_data;
  42. } else {
  43. return false;
  44. }
  45. }
  46. /**
  47. * @param array $data
  48. * @param int $id
  49. *
  50. * @return bool
  51. */
  52. public function updateData($data, $id) {
  53. $_map['id'] = $id;
  54. $_data = $data;
  55. $_rs = self::update($_data, $_map, true);
  56. if (false == $_rs) {
  57. return false;
  58. } else {
  59. return true;
  60. }
  61. }
  62. /**
  63. * @param string $trans_id 苹果订单号
  64. *
  65. * @return bool
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. * @throws \think\exception\DbException
  69. */
  70. public function getStatusByTransId($trans_id) {
  71. if (empty($trans_id)) {
  72. return false;
  73. }
  74. $_map['trans_id'] = $trans_id;
  75. $_status = self::where($_map)->field('cp_status, status')->find();
  76. if (false == $_status) {
  77. return false;
  78. }
  79. $_rdata['status'] = $_status['status'];
  80. $_rdata['cp_status'] = $_status['cp_status'];
  81. return $_rdata;
  82. }
  83. /**
  84. * 通过苹果订单号获取详情
  85. *
  86. * @param string $trans_id 苹果订单号
  87. *
  88. * @return array|false
  89. * @throws \think\Exception
  90. * @throws \think\db\exception\DataNotFoundException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. * @throws \think\exception\DbException
  93. */
  94. public function getInfoByTransId($trans_id) {
  95. if (empty($trans_id)) {
  96. return false;
  97. }
  98. $_map['trans_id'] = $trans_id;
  99. $_data = self::where($_map)->find();
  100. if (false == $_data) {
  101. return false;
  102. }
  103. $_data = $_data->toArray();
  104. return $_data;
  105. }
  106. /**
  107. * 通过订单号获取详情
  108. *
  109. * @param string $order_id 平台订单号
  110. *
  111. * @return array|false
  112. * @throws \think\Exception
  113. * @throws \think\db\exception\DataNotFoundException
  114. * @throws \think\db\exception\ModelNotFoundException
  115. * @throws \think\exception\DbException
  116. */
  117. public function getInfoByOrderId($order_id) {
  118. if (empty($order_id)) {
  119. return false;
  120. }
  121. $_map['order_id'] = $order_id;
  122. $_data = self::where($_map)->find();
  123. if (false == $_data) {
  124. return false;
  125. }
  126. $_data = $_data->toArray();
  127. return $_data;
  128. }
  129. /**
  130. * 获取最近订单信息
  131. *
  132. * @param string $end_time 结束时间
  133. * @param string $idfv IDFV
  134. * @param string $apple_id 苹果ID
  135. * @param string $product_id 商品ID
  136. *
  137. * @return array|false
  138. * @throws \think\Exception
  139. * @throws \think\db\exception\DataNotFoundException
  140. * @throws \think\db\exception\ModelNotFoundException
  141. * @throws \think\exception\DbException
  142. */
  143. public function getLastOrderData($end_time, $idfv, $apple_id, $product_id) {
  144. /* 3 天以内最近的订单 */
  145. $_end_time = $end_time;
  146. $_start_time = $_end_time - 3 * CommonConst::CONST_DAY_SECONDS;
  147. $_map['create_time'] = ['between', [$_start_time, $_end_time]];
  148. $_map['idfv'] = $idfv;
  149. $_map['apple_id'] = $apple_id;
  150. $_map['product_id'] = $product_id;
  151. $_map['trans_id'] = ['neq', ''];
  152. $_data = self::where($_map)->order('id desc')->find();
  153. if (false == $_data) {
  154. return false;
  155. }
  156. $_data = $_data->toArray();
  157. return $_data;
  158. }
  159. }