StoreFinanceFlow.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\store\finance;
  12. use app\model\store\SystemStore;
  13. use app\model\store\SystemStoreStaff;
  14. use app\model\user\User;
  15. use crmeb\basic\BaseModel;
  16. use crmeb\traits\ModelTrait;
  17. use think\Model;
  18. /**
  19. * 流水
  20. * Class StoreFinanceFlow
  21. * @package app\model\store\finance
  22. */
  23. class StoreFinanceFlow extends BaseModel
  24. {
  25. use ModelTrait;
  26. /**
  27. * 数据表主键
  28. * @var string
  29. */
  30. protected $pk = 'id';
  31. /**
  32. * 模型名称
  33. * @var string
  34. */
  35. protected $name = 'store_finance_flow';
  36. /**
  37. * 一对一关联用户表
  38. * @return \think\model\relation\HasOne
  39. */
  40. public function user()
  41. {
  42. return $this->hasOne(User::class, 'uid', 'uid')->field(['uid', 'nickname'])->bind([
  43. 'user_nickname' => 'nickname',
  44. ]);
  45. }
  46. /**
  47. * 一对一关联店员
  48. * @return mixed
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. */
  53. public function systemStoreStaff()
  54. {
  55. return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->field(['id', 'staff_name'])->bind([
  56. 'staff_name' => 'staff_name'
  57. ]);
  58. }
  59. /**
  60. * 一对一关联店员
  61. * @return mixed
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\DbException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. */
  66. public function systemStore()
  67. {
  68. return $this->hasOne(SystemStore::class, 'id', 'store_id');
  69. }
  70. /**
  71. * id搜索器
  72. * @param $query
  73. * @param $value
  74. */
  75. public function searchIdAttr($query, $value)
  76. {
  77. if (is_array($value)) {
  78. $query->whereIn('id', $value);
  79. } else {
  80. $query->where('id', $value);
  81. }
  82. }
  83. /**
  84. * 门店id搜索器
  85. * @param $query
  86. * @param $value
  87. */
  88. public function searchStoreIdAttr($query, $value)
  89. {
  90. if ($value !== '') {
  91. $query->where('store_id', $value);
  92. }
  93. }
  94. /**
  95. * 用户id
  96. * @param Model $query
  97. * @param $value
  98. */
  99. public function searchUidAttr($query, $value)
  100. {
  101. if ($value) $query->where('uid', $value);
  102. }
  103. /**
  104. * 用户id
  105. * @param Model $query
  106. * @param $value
  107. */
  108. public function searchTradeTypeAttr($query, $value)
  109. {
  110. if ($value) $query->where('trade_type', $value);
  111. }
  112. /**
  113. * 排除type
  114. * @param Model $query
  115. * @param $value
  116. */
  117. public function searchNoTypeAttr($query, $value)
  118. {
  119. if ($value) $query->where('type', '<>', $value);
  120. }
  121. /**
  122. * 店员id
  123. * @param Model $query
  124. * @param $value
  125. */
  126. public function searchStaffIdAttr($query, $value)
  127. {
  128. if ($value) {
  129. if ($value == -1) {//所有店员
  130. $query->where('staff_id', '>', 0);
  131. } else {
  132. $query->where('staff_id', $value);
  133. }
  134. }
  135. }
  136. /**
  137. * 交易单号
  138. * @param Model $query
  139. * @param $value
  140. */
  141. public function searchOrderIdAttr($query, $value)
  142. {
  143. if ($value !== '') {
  144. $query->where('order_id', 'LIKE', "%$value%");
  145. }
  146. }
  147. /**
  148. * 关联订单号
  149. * @param Model $query
  150. * @param $value
  151. */
  152. public function searchLinkIdAttr($query, $value)
  153. {
  154. if ($value !== '') $query->where('link_id', $value);
  155. }
  156. /**
  157. * 支出获取
  158. * @param Model $query
  159. * @param $value
  160. */
  161. public function searchPmAttr($query, $value)
  162. {
  163. if ($value !== '') $query->where('pm', $value);
  164. }
  165. /**
  166. * 类型
  167. * @param Model $query
  168. * @param $value
  169. */
  170. public function searchTypeAttr($query, $value)
  171. {
  172. if ($value) {
  173. if (is_array($value)) {
  174. $query->where('type', 'in', $value);
  175. } else {
  176. $query->where('type', $value);
  177. }
  178. }
  179. }
  180. /**
  181. * 支付类型
  182. * @param Model $query
  183. * @param $value
  184. */
  185. public function searchPayTypeAttr($query, $value)
  186. {
  187. if ($value !== '') $query->where('pay_type', $value);
  188. }
  189. /**
  190. * 删除
  191. * @param Model $query
  192. * @param $value
  193. */
  194. public function searchIsDelAttr($query, $value)
  195. {
  196. if ($value !== '') $query->where('is_del', $value);
  197. }
  198. }