Lecturer.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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\merchant\model\special;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use app\merchant\model\order\StoreOrder as StoreOrderModel;
  15. use app\merchant\model\special\Special;
  16. use app\merchant\model\merchant\Merchant;
  17. /**
  18. * Class Lecturer 讲师
  19. * @package app\merchant\model\special
  20. */
  21. class Lecturer extends ModelBasic
  22. {
  23. use ModelTrait;
  24. //设置where条件
  25. public static function setWhere($where, $alirs = '', $model = null)
  26. {
  27. $model = $model === null ? new self() : $model;
  28. $model = $alirs !== '' ? $model->alias($alirs) : $model;
  29. $alirs = $alirs === '' ? $alirs : $alirs . '.';
  30. $model = $model->where("{$alirs}is_del", 0);
  31. if (isset($where['is_show']) && $where['is_show'] !== '') $model = $model->where("{$alirs}is_show", $where['is_show']);
  32. if ($where['title'] && $where['title']) $model = $model->where("{$alirs}lecturer_name", 'LIKE', "%$where[title]%");
  33. $model = $model->order("{$alirs}sort desc");
  34. return $model;
  35. }
  36. public static function getRecommendLecturerList($where, $lecturer)
  37. {
  38. $data = self::setWhere($where)->where('id', 'not in', $lecturer)->page((int)$where['page'], (int)$where['limit'])->select();
  39. $data = count($data) ? $data->toArray() : [];
  40. $count = self::setWhere($where)->where('id', 'not in', $lecturer)->count();
  41. return compact('data', 'count');
  42. }
  43. /**讲师列表
  44. * @param $where
  45. * @return array
  46. * @throws \think\Exception
  47. */
  48. public static function getLecturerList($where)
  49. {
  50. $data = self::setWhere($where)->page((int)$where['page'], (int)$where['limit'])->select();
  51. $data = count($data) ? $data->toArray() : [];
  52. $count = self::setWhere($where)->count();
  53. return compact('data', 'count');
  54. }
  55. /**
  56. * 删除讲师
  57. * @param $id
  58. * @return bool|int
  59. * @throws \think\exception\DbException
  60. */
  61. public static function delLecturer($id)
  62. {
  63. $lecturer = self::get($id);
  64. if (!$lecturer) return self::setErrorInfo('删除的数据不存在');
  65. Special::where('is_del', 0)->where('lecturer_id', $id)->update(['lecturer_id' => 0]);
  66. if ($lecturer['mer_id'] > 0) {
  67. Merchant::where('id', $lecturer['mer_id'])->update(['is_del' => 1]);
  68. }
  69. return self::where('id', $id)->update(['is_del' => 1]);
  70. }
  71. /**获取商户id
  72. * @param $id
  73. */
  74. public static function getMerId($id)
  75. {
  76. return self::where('id', $id)->value('mei_id');
  77. }
  78. /**讲师课程订单
  79. * @param $lecturer_id
  80. */
  81. public static function lecturerOrderList($where)
  82. {
  83. $model = self::getOrderWhere($where)->field('a.order_id,a.pay_price,a.pay_type,a.paid,a.status,a.total_price,a.refund_status,a.type,s.title,r.nickname,a.uid');
  84. $data = ($data = $model->page((int)$where['page'], (int)$where['limit'])->select()) && count($data) ? $data->toArray() : [];
  85. foreach ($data as $key => &$value) {
  86. if ($value['paid'] == 0) {
  87. $value['status_name'] = '未支付';
  88. } else if ($value['paid'] == 1 && $value['status'] == 0 && $value['refund_status'] == 0 && $value['type'] != 2) {
  89. $value['status_name'] = '已支付';
  90. } else if ($value['paid'] == 1 && $value['status'] == 0 && $value['refund_status'] == 1 && $value['type'] != 2) {
  91. $value['status_name'] = '退款中';
  92. } else if ($value['paid'] == 1 && $value['status'] == 0 && $value['refund_status'] == 2 && $value['type'] != 2) {
  93. $value['status_name'] = '已退款';
  94. }
  95. if ($value['nickname']) {
  96. $value['nickname'] = $value['nickname'] . '/' . $value['uid'];
  97. } else {
  98. $value['nickname'] = '暂无昵称/' . $value['uid'];
  99. }
  100. if ($value['paid'] == 1) {
  101. switch ($value['pay_type']) {
  102. case 'weixin':
  103. $value['pay_type_name'] = '微信支付';
  104. break;
  105. case 'yue':
  106. $value['pay_type_name'] = '余额支付';
  107. break;
  108. case 'zhifubao':
  109. $value['pay_type_name'] = '支付宝支付';
  110. break;
  111. default:
  112. $value['pay_type_name'] = '其他支付';
  113. break;
  114. }
  115. } else {
  116. switch ($value['pay_type']) {
  117. default:
  118. $value['pay_type_name'] = '未支付';
  119. break;
  120. }
  121. }
  122. }
  123. $count = self::getOrderWhere($where)->count();
  124. return compact('count', 'data');
  125. }
  126. /**条件处理
  127. * @param $where
  128. * @return StoreOrderModel
  129. */
  130. public static function getOrderWhere($where)
  131. {
  132. $model = StoreOrderModel::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT')
  133. ->join('Special s', 'a.cart_id=s.id')
  134. ->where('a.type', 0)->where('a.paid', 1);
  135. if ($where['lecturer_id']) {
  136. $model = $model->where('s.lecturer_id', $where['lecturer_id']);
  137. }
  138. if ($where['data'] !== '') {
  139. $model = self::getModelTime($where, $model, 'a.add_time');
  140. }
  141. $model = $model->order('a.id desc');
  142. return $model;
  143. }
  144. /**
  145. * 处理订单金额
  146. * @param $where
  147. * @return array
  148. */
  149. public static function getOrderPrice($where)
  150. {
  151. $price = array();
  152. $price['pay_price'] = 0;//支付金额
  153. $price['pay_price_wx'] = 0;//微信支付金额
  154. $price['pay_price_yue'] = 0;//余额支付金额
  155. $price['pay_price_zhifubao'] = 0;//支付宝支付金额
  156. $list = self::getOrderWhere($where)->field([
  157. 'sum(a.total_num) as total_num',
  158. 'sum(a.pay_price) as pay_price',
  159. ])->find()->toArray();
  160. $price['total_num'] = $list['total_num'];//商品总数
  161. $price['pay_price'] = $list['pay_price'];//支付金额
  162. $list = self::getOrderWhere($where)->field('sum(a.pay_price) as pay_price,a.pay_type')->group('a.pay_type')->select()->toArray();
  163. foreach ($list as $v) {
  164. if ($v['pay_type'] == 'weixin') {
  165. $price['pay_price_wx'] = $v['pay_price'];
  166. } elseif ($v['pay_type'] == 'yue') {
  167. $price['pay_price_yue'] = $v['pay_price'];
  168. } elseif ($v['pay_type'] == 'zhifubao') {
  169. $price['pay_price_zhifubao'] = $v['pay_price'];
  170. } else {
  171. $price['pay_price_other'] = $v['pay_price'];
  172. }
  173. }
  174. $price['order_sum'] = self::getOrderWhere($where)->count();
  175. return $price;
  176. }
  177. public static function getBadge($where)
  178. {
  179. $price = self::getOrderPrice($where);
  180. return [
  181. [
  182. 'name' => '订单数量',
  183. 'field' => '件',
  184. 'count' => $price['order_sum'],
  185. 'background_color' => 'layui-bg-blue',
  186. 'col' => 4
  187. ],
  188. [
  189. 'name' => '售出课程',
  190. 'field' => '件',
  191. 'count' => $price['total_num'],
  192. 'background_color' => 'layui-bg-blue',
  193. 'col' => 4
  194. ],
  195. [
  196. 'name' => '订单金额',
  197. 'field' => '元',
  198. 'count' => $price['pay_price'],
  199. 'background_color' => 'layui-bg-blue',
  200. 'col' => 4
  201. ],
  202. [
  203. 'name' => '微信支付金额',
  204. 'field' => '元',
  205. 'count' => $price['pay_price_wx'],
  206. 'background_color' => 'layui-bg-blue',
  207. 'col' => 4
  208. ],
  209. [
  210. 'name' => '余额支付金额',
  211. 'field' => '元',
  212. 'count' => $price['pay_price_yue'],
  213. 'background_color' => 'layui-bg-blue',
  214. 'col' => 4
  215. ],
  216. [
  217. 'name' => '支付宝支付金额',
  218. 'field' => '元',
  219. 'count' => $price['pay_price_zhifubao'],
  220. 'background_color' => 'layui-bg-blue',
  221. 'col' => 4
  222. ]
  223. ];
  224. }
  225. /**生成讲师
  226. * @param $data
  227. * @param $mer_id
  228. * @return object
  229. */
  230. public static function addLecturer($data, $mer_id)
  231. {
  232. $array = [
  233. 'mer_id' => $mer_id,
  234. 'lecturer_name' => $data['merchant_name'],
  235. 'lecturer_head' => $data['merchant_head'],
  236. 'phone' => $data['link_tel'],
  237. 'label' => $data['label'],
  238. 'introduction' => $data['introduction'],
  239. 'explain' => $data['explain'],
  240. 'add_time' => time()
  241. ];
  242. $res = self::set($array);
  243. return $res;
  244. }
  245. }