CustomerZueCoinModel.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\common\model;
  3. class CustomerZueCoinModel extends BaseModel
  4. {
  5. protected $table = 'erp_customer_zue_coin';
  6. protected function genSchema(array $schema)
  7. {
  8. // TODO: Implement genSchema() method.
  9. }
  10. /**
  11. * @return \think\model\relation\HasOne
  12. */
  13. public function customer()
  14. {
  15. return self::hasOne(CustomerModel::class,'id','customer_id')->where('is_delete',0);
  16. }
  17. public function record() {
  18. return self::hasMany(ZueCoinRecordModel::class,'zue_coin_id','id')->where('is_delete',0)->order('create_time', 'desc');
  19. }
  20. /**
  21. * @param array $params
  22. * @return \think\Paginator
  23. * @throws \think\db\exception\DbException
  24. */
  25. public function findByPaginate(array $params) {
  26. $where = [];
  27. if ($params['customer']) {
  28. $where = [['id|name_zh|name_en', 'like', '%'.$params['customer'].'%']];
  29. }
  30. return $this->where('erp_customer_zue_coin.is_delete',0)
  31. ->with('customer')
  32. ->hasWhere('customer', $where)
  33. ->paginate(['list_rows'=>10, "query" => $params]);
  34. }
  35. public function findById($id) {
  36. return $this->where([
  37. ['id' ,'=', $id],
  38. ['is_delete', '=', 0]
  39. ])->with(['customer', 'record'])->find();
  40. }
  41. public function findByCustomerId($c_id) {
  42. return $this->where([
  43. ['is_delete', '=', 0],
  44. ['lose_time', '>=', time()],
  45. ])->order('lose_time', 'Asc')->find();
  46. }
  47. }