CommonLogic.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace app\mobile\logic;
  3. use app\model\AccountModel;
  4. use app\model\CommonModel;
  5. use app\model\GroupModel;
  6. use app\model\ServiceModel;
  7. use app\model\ThemeModel;
  8. use app\model\VideoModel;
  9. use think\Exception;
  10. use think\facade\Db;
  11. use think\response\Json;
  12. //公共
  13. class CommonLogic extends BaseLogic
  14. {
  15. //视频列表
  16. public static function getVideoList(array $data = []): Json
  17. {
  18. $rs = AccountModel::field('id,video_ids')
  19. ->where(['id' => self::$aid, 'is_del' => CommonModel::$del_normal])
  20. ->findOrEmpty()
  21. ->toArray();
  22. if (empty($rs)) return json_show(CommonModel::$error_param, '该账户不存在');
  23. $db = VideoModel::where(['is_del' => CommonModel::$del_normal, 'status' => CommonModel::$status_normal])
  24. ->whereIn('id', $rs['video_ids']);
  25. $count = $db->count('id');
  26. $list = $db
  27. ->field('id,video_sn,video_name,video_url,video_img')
  28. ->page($data['page'], $data['size'])
  29. ->order(['weight' => 'desc', 'id' => 'desc'])
  30. ->select()
  31. ->toArray();
  32. return json_show(CommonModel::$success, '获取视频列表成功', ['count' => $count, 'list' => $list]);
  33. }
  34. //手机主题
  35. public static function theme(): Json
  36. {
  37. $rs = ThemeModel::field('id,code')
  38. ->where(['is_del' => CommonModel::$del_normal, 'group_id' => self::$group_id, 'status' => CommonModel::$status_normal])
  39. ->append(['modular'])
  40. ->withAttr('modular', function ($val, $data) {
  41. return Db::name('theme_modular')
  42. ->field('id,title,type')
  43. ->where(['is_del' => CommonModel::$del_normal, 'theme_id' => $data['id'], 'status' => CommonModel::$status_normal])
  44. ->order(['addtime' => 'desc', 'id' => 'desc'])
  45. ->append(['data'])
  46. ->withAttr('data', function ($v, $d) {
  47. return Db::name('theme_modular_data')
  48. ->field('id,img,jump_type,jump_param,good_name,good_id,style_type')
  49. ->where(['is_del' => CommonModel::$del_normal, 'theme_modular_id' => $d['id']])
  50. ->order(['addtime' => 'desc', 'id' => 'desc'])
  51. ->select()
  52. ->toArray();
  53. })
  54. ->select()
  55. ->toArray();
  56. })
  57. ->findOrEmpty()
  58. ->toArray();
  59. return empty($rs) ? json_show(CommonModel::$error_param, '该手机主题不存在') : json_show(CommonModel::$success, '获取手机主题成功', $rs);
  60. }
  61. //微信支付预下单
  62. public static function getPrepayId(array $data = []): json
  63. {
  64. $openId = AccountModel::where(['id' => self::$aid, 'is_del' => CommonModel::$del_normal])
  65. ->value('wx_openId', '');
  66. if ($openId == '') return json_show(CommonModel::$error_token, '获取账户openId失败,请重新登录');
  67. Db::startTrans();
  68. try {
  69. $amount = '0';//支付金额
  70. if($data['type'] == CommonModel::$pay_type_service){
  71. //购买服务
  72. $rs=ServiceModel::field('id,original_price,activity_price,title,activity_status')
  73. ->whereIn('id',array_column($data['list'],'id'))
  74. ->where(['is_del'=>CommonModel::$del_normal,'status'=>CommonModel::$status_normal])
  75. ->select()
  76. ->toArray();
  77. if(empty($rs)) throw new Exception('购买的服务不存在或已下架');
  78. foreach ($rs as $item){
  79. if($item['activity_status'] == ServiceModel::$activity_status_ing) $amount = bcadd($amount,bcmul($rs['activity_price'],$),2);
  80. }
  81. }
  82. Db::commit();
  83. return json_show(CommonModel::$success, '微信支付预下单成功', $res);
  84. } catch (Exception $exception) {
  85. Db::rollback();
  86. return json_show(CommonModel::$success, '微信支付预下单失败' . $exception->getMessage());
  87. }
  88. }
  89. }