Merchant.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\merchant;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use service\HookService;
  15. use service\SystemConfigService;
  16. /**
  17. * Class Merchant
  18. * @package app\merchant\model\merchant
  19. */
  20. class Merchant extends ModelBasic
  21. {
  22. use ModelTrait;
  23. //设置where条件
  24. public static function setWhere($where, $alirs = '', $model = null)
  25. {
  26. $model = $model === null ? new self() : $model;
  27. $model = $alirs !== '' ? $model->alias($alirs) : $model;
  28. $alirs = $alirs === '' ? $alirs : $alirs . '.';
  29. $model = $model->where("{$alirs}is_del", 0);
  30. if ($where['title'] && $where['title']) $model = $model->where("{$alirs}mer_name", 'LIKE', "%$where[title]%");
  31. return $model;
  32. }
  33. /**讲师列表
  34. * @param $where
  35. * @return array
  36. * @throws \think\Exception
  37. */
  38. public static function getLecturerMerchantList($where)
  39. {
  40. $data = self::setWhere($where)->page((int)$where['page'], (int)$where['limit'])->select();
  41. $data = count($data) ? $data->toArray() : [];
  42. $count = self::setWhere($where)->count();
  43. return compact('data', 'count');
  44. }
  45. /**
  46. * 删除讲师后台
  47. * @param $id
  48. * @return bool|int
  49. * @throws \think\exception\DbException
  50. */
  51. public static function delMerchant($id)
  52. {
  53. return self::where('id', $id)->update(['is_del' => 1]);
  54. }
  55. public static function getMerWhere()
  56. {
  57. return self::where(['is_del' => 0, 'estate' => 1, 'status' => 1]);
  58. }
  59. /**减讲师余额
  60. * @param $mer_id
  61. * @param $price
  62. * @return int|true
  63. * @throws \think\Exception
  64. */
  65. public static function decMerchantNowMoney($mer_id, $price)
  66. {
  67. return self::where('id', $mer_id)->setDec('now_money', $price);
  68. }
  69. /**讲师列表
  70. * @return false|\PDOStatement|string|\think\Collection
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. * @throws \think\exception\DbException
  74. */
  75. public static function getMerchantList()
  76. {
  77. return self::getMerWhere()->field('id,mer_name')->select();
  78. }
  79. }