MCustomerCard.Class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * 商铺管理模块
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/10/31
  7. * Time: 15:02
  8. */
  9. namespace JinDouYun\Model\Customer;
  10. use Exception;
  11. use JinDouYun\Dao\Customer\DCustomerCard;
  12. use JinDouYun\Dao\Customer\DCustomerCardNum;
  13. use Mall\Framework\Core\ErrorCode;
  14. use Mall\Framework\Core\StatusCode;
  15. use Mall\Framework\Core\ResultWrapper;
  16. use JinDouYun\Model\MBaseModel;
  17. use Monolog\Handler\IFTTTHandler;
  18. class MCustomerCard extends MBaseModel
  19. {
  20. private $obj;
  21. private $cutTable = 250000;
  22. private $enterpriseId;
  23. private $userCenterId;
  24. private $DCardNum;
  25. public function __construct($enterpriseId, $userCenterId = '')
  26. {
  27. $this->enterpriseId = $enterpriseId;
  28. $this->userCenterId = $userCenterId;
  29. parent::__construct($this->enterpriseId, $this->userCenterId);
  30. $this->obj = new DCustomerCard('default');
  31. $this->DCardNum = new DCustomerCardNum('default');
  32. }
  33. /**
  34. * 列表
  35. * @param $where
  36. * @return mixed
  37. */
  38. public function list($where)
  39. {
  40. $limit = $where['limit'];
  41. unset($where['limit']);
  42. $offset = $where['offset'];
  43. unset($where['offset']);
  44. $join = 'Left Join qianniao_customer_'.$this->enterpriseId.' AS b on a.customer_id = b.id';
  45. $join .= ' Left Join qianniao_shop_card AS c on a.card_id = c.id';
  46. $wherein[] = ['a.enterprise_id' ,'=' ,$this->enterpriseId];
  47. $dbResult = $this->obj->select($wherein, 'a.*,b.name as user_name,c.name', 'id DESC', $limit, $offset, array(), true, false,$join);
  48. $count = $this->obj->count($wherein);
  49. if ($dbResult === false) {
  50. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  51. }
  52. $return = [
  53. 'data' => $dbResult,
  54. 'total' => $count,
  55. ];
  56. if($return === false){
  57. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  58. }else{
  59. return ResultWrapper::success($return);
  60. }
  61. }
  62. /**
  63. * 详情
  64. * @param $where
  65. * @return mixed
  66. */
  67. public function details($where)
  68. {
  69. $limit = $where['limit'];
  70. unset($where['limit']);
  71. $offset = $where['offset'];
  72. unset($where['offset']);
  73. $join = ' Left Join qianniao_shop_project AS b on a.project_id = b.id';
  74. $wherein[] = ['a.customer_card' ,'=' ,$where['id']];
  75. $dbResult = $this->DCardNum->select($wherein, 'a.*,b.name', 'id DESC', $limit, $offset, array(), true, false,$join);
  76. $count = $this->DCardNum->count($wherein);
  77. if ($dbResult === false) {
  78. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  79. }
  80. $return = [
  81. 'data' => $dbResult,
  82. 'total' => $count,
  83. ];
  84. if($return === false){
  85. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  86. }else{
  87. return ResultWrapper::success($return);
  88. }
  89. }
  90. /**
  91. * Doc: (des="添加")
  92. * User: XMing
  93. * Date: 2020/7/15
  94. * Time: 10:42 上午
  95. * @throws Exception
  96. * @param array $params
  97. * @return ResultWrapper
  98. */
  99. public function insert(array $params)
  100. {
  101. $res = $this->obj->insert($params);
  102. if ($res){
  103. return ResultWrapper::success('添加成功');
  104. }else{
  105. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  106. }
  107. }
  108. public function update($params, $id)
  109. {
  110. $data = $this->obj->get($id);
  111. if (!$data){
  112. return ResultWrapper::fail('数据不存在', ErrorCode::$dberror);
  113. }
  114. $dbResult = $this->obj->update($params,$id);
  115. if($dbResult === false){
  116. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  117. }
  118. return ResultWrapper::success('修改成功');
  119. }
  120. /**
  121. * 格式数据详情
  122. * @param $data
  123. * @return mixed
  124. */
  125. public function formatInfo($data)
  126. {
  127. return $data;
  128. }
  129. public function delete($id)
  130. {
  131. $res = $this->obj->delete(['id' => $id]);
  132. if ($res){
  133. return ResultWrapper::success('删除成功');
  134. }
  135. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  136. }
  137. }