AccountOrderModel.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * AccountOrderModel.php UTF-8
  4. *
  5. *
  6. * @date : 2018/6/13 14:33
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huoAccountDeal\model;
  13. use huo\model\common\CommonModel;
  14. use huo\model\game\GameModel;
  15. use huo\model\member\MemberModel;
  16. use huo\model\member\MemGameModel;
  17. use huolib\constant\OrderConst;
  18. class AccountOrderModel extends CommonModel {
  19. protected $name = 'account_order';
  20. // 开启自动写入时间戳字段
  21. protected $autoWriteTimestamp = true;
  22. public function mg() {
  23. return $this->belongsTo(MemGameModel::className(), 'ags_id', 'id');
  24. }
  25. public function game() {
  26. return $this->belongsTo(GameModel::className(), 'app_id', 'id');
  27. }
  28. public function goods() {
  29. return $this->belongsTo(AccountGoodsModel::className(), 'ags_id', 'id');
  30. }
  31. public function seller() {
  32. return $this->belongsTo(MemberModel::className(), 'sell_mem_id', 'id');
  33. }
  34. public function buyer() {
  35. return $this->belongsTo(MemberModel::className(), 'buy_mem_id', 'id');
  36. }
  37. public function addData($data) {
  38. if (empty($data)) {
  39. return false;
  40. }
  41. if ($_obj = self::create($data, true)) {
  42. return $_obj->id;
  43. } else {
  44. return false;
  45. }
  46. }
  47. public function updateData($_data, $am_id) {
  48. $_map['id'] = $am_id;
  49. $_rs = self::update($_data, $_map, true);
  50. if (false == $_rs) {
  51. return false;
  52. } else {
  53. return true;
  54. }
  55. }
  56. public function getSellCnt($mem_id) {
  57. return $this->where(['sell_mem_id' => $mem_id, 'status' => OrderConst::PAY_STATUS_SUC])->count();
  58. }
  59. public function getBuyCnt($mem_id) {
  60. return $this->where(['buy_mem_id' => $mem_id, 'status' => OrderConst::PAY_STATUS_SUC])->count();
  61. }
  62. public function getStatus($order_id) {
  63. $_map['order_id'] = $order_id;
  64. $_status = $this->where($_map)->value('status');
  65. if (false == $_status) {
  66. return false;
  67. }
  68. $_rdata['status'] = $_status;
  69. return $_rdata;
  70. }
  71. public function getInfoByOrderId($order_id) {
  72. $_map['order_id'] = $order_id;
  73. $_info = $this->where($_map)->find();
  74. if (false === $_info) {
  75. return false;
  76. }
  77. if (is_object($_info)) {
  78. return $_info->toArray();
  79. } else {
  80. return $_info;
  81. }
  82. }
  83. /**
  84. * @param $order_id
  85. *
  86. * @return array|false
  87. */
  88. public function getDetail($order_id) {
  89. $_map['order_id'] = $order_id;
  90. $_data = $this->where($_map)->find();
  91. if (false == $_data) {
  92. return false;
  93. }
  94. if (is_object($_data)) {
  95. $_data = $_data->toArray();
  96. }
  97. return $_data;
  98. }
  99. /**
  100. * @param array $data
  101. * @param string $id
  102. *
  103. * @return bool
  104. */
  105. public function updateOrder($data, $id) {
  106. $_map['id'] = $id;
  107. $_data = $data;
  108. $_rs = self::update($_data, $_map, true);
  109. if (false == $_rs) {
  110. return false;
  111. } else {
  112. return true;
  113. }
  114. }
  115. }