MConsume.Class.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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\Stock;
  10. use Exception;
  11. use JinDouYun\Dao\Department\DStaff;
  12. use JinDouYun\Dao\Stock\DConsume;
  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 MConsume extends MBaseModel
  19. {
  20. private $obj;
  21. private $cutTable = 250000;
  22. private $enterpriseId;
  23. private $userCenterId;
  24. private $DCardBind;
  25. private $DCard;
  26. public function __construct($enterpriseId, $userCenterId = '')
  27. {
  28. $this->enterpriseId = $enterpriseId;
  29. $this->userCenterId = $userCenterId;
  30. parent::__construct($this->enterpriseId, $this->userCenterId);
  31. $this->obj = new DConsume('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. $wherein['a.enterpriseId'] = $this->enterpriseId;
  45. if (isset($where['shopId'])) {
  46. $wherein['a.shopId'] = $where['shopId'];
  47. }
  48. if (isset($where['status'])) {
  49. $wherein['a.status'] = $where['status'];
  50. }
  51. if (isset($where['mobile'])) {
  52. $wherein['u.mobile'] = $where['mobile'];
  53. }
  54. if (isset($where['write_mobile'])) {
  55. $wherein['c.mobile'] = $where['write_mobile'];
  56. }
  57. if (isset($where['name'])){
  58. $wherein[] = ['a.name', 'like', '%'.$where['name'].'%'];
  59. }
  60. if (isset($where['start_time']))
  61. {
  62. $wherein[] = ['a.createTime', '>=', strtotime($where['start_time'])];
  63. }
  64. if (isset($where['end_time']))
  65. {
  66. $wherein[] = ['a.createTime', '<=', strtotime($where['end_time'])];
  67. }
  68. $join = 'Left Join qianniao_shop_1 as b on a.shopId = b.id';
  69. $join .= ' Left Join qianniao_user_center as u on a.userCenterId = u.id';
  70. $join .= ' Left Join qianniao_user_center as c on a.write = c.id';
  71. // $join .= ' Left Join qianniao_user_bind_enterprise as d on d.userCenterId = u.id';
  72. // $join .= ' Left Join qianniao_user_bind_enterprise as e on e.userCenterId = c.id';
  73. $dbResult = $this->obj->select($wherein, 'a.*,b.name as shop_name,u.mobile,c.mobile as write_mobile', 'id DESC', $limit, $offset, array(), true, false,$join);
  74. $count = $this->obj->count($wherein, array(), $join);
  75. if ($dbResult === false) {
  76. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  77. }
  78. $staff = new DStaff('default');
  79. $staff->setTable('qianniao_staff_'.$this->enterpriseId);
  80. foreach ($dbResult as &$item)
  81. {
  82. $item['write_off_person'] = '';
  83. $item['transferor'] = '';
  84. if ($item['userCenterId']){
  85. $staffs = $staff->get(['userCenterId' => $item['userCenterId']]);
  86. if ($staffs){
  87. $item['transferor'] = $staffs['staffName'];
  88. }else{
  89. $item['transferor'] = '总账号';
  90. }
  91. }
  92. if ($item['write']){
  93. $staffs = $staff->get(['userCenterId' => $item['write']]);
  94. if ($staffs){
  95. $item['write_off_person'] = $staffs['staffName'];
  96. }else {
  97. $item['write_off_person'] = '总账号';
  98. }
  99. }
  100. }
  101. $return = [
  102. 'data' => $dbResult,
  103. 'total' => $count,
  104. ];
  105. if ($return === false) {
  106. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  107. } else {
  108. return ResultWrapper::success($return);
  109. }
  110. }
  111. /**
  112. * 详情
  113. * @param $where
  114. * @return mixed
  115. */
  116. public function details($where)
  117. {
  118. if (empty($where)) {
  119. return ResultWrapper::success($where);
  120. }
  121. $dbResult = $this->obj->get($where);
  122. if ($dbResult === false) {
  123. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  124. }
  125. return ResultWrapper::success(self::formatInfo($dbResult));
  126. }
  127. /**
  128. * Doc: (des="添加")
  129. * User: XMing
  130. * Date: 2020/7/15
  131. * Time: 10:42 上午
  132. * @param array $params
  133. * @return ResultWrapper
  134. * @throws Exception
  135. */
  136. public function insert(array $params)
  137. {
  138. $res = $this->obj->insert($params);
  139. if ($res) {
  140. return ResultWrapper::success('添加成功');
  141. } else {
  142. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  143. }
  144. }
  145. public function update($params, $id)
  146. {
  147. $data = $this->obj->get($id);
  148. if (!$data) {
  149. return ResultWrapper::fail('数据不存在', ErrorCode::$dberror);
  150. }
  151. $dbResult = $this->obj->update($params, $id);
  152. if ($dbResult === false) {
  153. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  154. }
  155. return ResultWrapper::success('成功');
  156. }
  157. /**
  158. * 格式数据详情
  159. * @param $data
  160. * @return mixed
  161. */
  162. public function formatInfo($data)
  163. {
  164. return $data;
  165. }
  166. public function delete($where)
  167. {
  168. $res = $this->obj->delete($where);
  169. if ($res) {
  170. return ResultWrapper::success('删除成功');
  171. }
  172. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  173. }
  174. }