AccountGoodsModel.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * AccountGoodsModel.php UTF-8
  4. *
  5. *
  6. * @date : 2018/6/12 18:31
  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 huolib\constant\AccountConst;
  15. use huolib\constant\CommonConst;
  16. class AccountGoodsModel extends CommonModel {
  17. protected $name = 'account_goods';
  18. // 开启自动写入时间戳字段
  19. protected $autoWriteTimestamp = true;
  20. public function mem() {
  21. return $this->belongsTo('huo\model\member\MemberModel', 'mem_id', 'id');
  22. }
  23. public function game() {
  24. return $this->belongsTo('huo\model\game\GameModel', 'app_id', 'id')->field('id,name,icon,publicity');
  25. }
  26. public function account() {
  27. return $this->belongsTo('huo\model\member\MemGameModel', 'mg_mem_id', 'id');
  28. }
  29. protected function base($query) {
  30. $query->where('is_delete', '=', CommonConst::CONST_NOT_DELETE);
  31. }
  32. public function addData($data) {
  33. if (empty($data)) {
  34. return false;
  35. }
  36. if ($_obj = self::create($data, true)) {
  37. return $_obj->id;
  38. } else {
  39. return false;
  40. }
  41. }
  42. public function updateData($_data, $ags_id) {
  43. $_map['id'] = $ags_id;
  44. $_rs = self::update($_data, $_map, true);
  45. if (false == $_rs) {
  46. return false;
  47. } else {
  48. return true;
  49. }
  50. }
  51. public function getIdsByTitle($title) {
  52. return $this->where(['title' => ['like', "%{$title}%"]])->column('id');
  53. }
  54. public function isSell($mg_mem_id) {
  55. $_map['status'] = ['in', [
  56. AccountConst::STATUS_AUDITING,
  57. AccountConst::STATUS_PULL_ON_SHELVES,
  58. AccountConst::STATUS_LOCKED,
  59. ]];
  60. $_map['mg_mem_id'] = $mg_mem_id;
  61. $_cnt = $this->where($_map)->count();
  62. if ($_cnt > 0) {
  63. return AccountConst::ACCOUNT_IS_SELL;
  64. }
  65. return 0;
  66. }
  67. }