AppController.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. <?php
  2. namespace General\Controllers\CompanyAuth;
  3. use App\Consts\SysConsts;
  4. use App\Http\Controllers\Controller;
  5. use General\Controllers\CompanyAuth\Transformers\ActivityTransformer;
  6. use General\Controllers\CompanyAuth\Transformers\ChannelTransformer;
  7. use General\Controllers\CompanyAuth\Transformers\CustomSendMsgsTransformers;
  8. use General\Controllers\CompanyAuth\Transformers\DelaySendMsgsTransformers;
  9. use General\Controllers\CompanyAuth\Transformers\OfficialAccountTransformer;
  10. use General\Controllers\CompanyAuth\Transformers\OrderDayStatsTransformer;
  11. use General\Controllers\CompanyAuth\Transformers\OrderTransformer;
  12. use General\Controllers\CompanyAuth\Transformers\SendOrderTransformer;
  13. use General\Helpers\CommonHelper;
  14. use General\Requests\CompanyAuth\BookQueryRequest;
  15. use General\Requests\CompanyAuth\CustomSendMsgRequest;
  16. use General\Requests\CompanyAuth\ChannelQueryRequest;
  17. use General\Requests\CompanyAuth\SingleSendOrderRequest;
  18. use General\Services\Activity\ActivityService;
  19. use General\Services\BaseAuthConfig;
  20. use General\Services\Book\BookConfigService;
  21. use General\Services\Channel\ChannelService;
  22. use General\Services\OfficialAccount\OfficialAccountService;
  23. use General\Services\Order\OrderService;
  24. use General\Services\SendOrder\SendOrderService;
  25. use General\Services\SendOrder\SendOrderStatistic;
  26. use Illuminate\Support\Facades\DB;
  27. use Illuminate\Http\Request;
  28. class AppController extends Controller
  29. {
  30. use BaseAuthConfig;
  31. /**
  32. * @apiDefine CompanyAuth 第三方授权接口
  33. */
  34. /**
  35. * @api {post} company/auth/channels 授权站点列表
  36. * @apiVersion 1.0.0
  37. * @apiName channels
  38. * @apiGroup CompanyAuth
  39. * @apiParam {String} is_enabled 状态(0.未启用 1.已启用)
  40. * @apiParam {String} phone 手机号
  41. * @apiParam {String} app_id 分配好的{app_id}
  42. * @apiParam {String} nonce_str 随机字符串
  43. * @apiParam {String} timestamp 时间戳
  44. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  45. * @apiError {int} code 状态码
  46. * @apiError {String} msg 信息
  47. * @apiErrorExample {json} Error-Response:
  48. * HTTP/1.1 200 OK
  49. * [
  50. * {
  51. * 'code' : 10030,
  52. * 'msg' : '未授权!'
  53. * },
  54. * {
  55. * 'code' : 10031,
  56. * 'msg' : 'IP未授权!'
  57. * },
  58. * {
  59. * 'code' : 10032,
  60. * 'msg' : '授权时间已过期!'
  61. * },
  62. * {
  63. * 'code' : 10033,
  64. * 'msg' : '授权签名错误!'
  65. * },
  66. * {
  67. * 'code' : 10034,
  68. * 'msg' : '查询数据为空!'
  69. * },
  70. * {
  71. * 'code' : 10035,
  72. * 'msg' : '查询数据时间长度不能超过30天!'
  73. * },
  74. * {
  75. * 'code' : 1002,
  76. * 'msg' : '查询参数错误!'
  77. * },
  78. * ]
  79. * @apiSuccess {int} code 状态码
  80. * @apiSuccess {String} msg 信息
  81. * @apiSuccess {Object} data 结果集
  82. * @apiSuccess {Int} id 渠道ID
  83. * @apiSuccess {String} name 渠道名称
  84. * @apiSuccess {String} created_at 创建时间
  85. * @apiSuccess {String} site_nick_name 站点昵称
  86. * @apiSuccess {String} is_enabled 状态(0.未启用 1.已启用)
  87. * @apiSuccess {String} phone 手机号
  88. * @apiSuccessExample {json} Success-Response:
  89. * HTTP/1.1 200 OK
  90. * {
  91. * "code": 0,
  92. * "msg": "",
  93. * "data": [
  94. * {
  95. * "id": 130,
  96. * "name": "杭州微点",
  97. * "created_at": "2018-01-05 09:57:37",
  98. * "site_nick_name": "2018-01-05 09:57:37",
  99. * "is_enabled": "1",
  100. * "phone": "13888888888"
  101. * }
  102. * ]
  103. * }
  104. */
  105. public function channels(Request $request)
  106. {
  107. $is_enabled = $request->get('is_enabled', '');
  108. $phone = $request->get('phone', '');
  109. $service = new ChannelService;
  110. $channels = $service->getChannelsByChannelUserIds($this->channel_user_ids, $is_enabled, $phone);
  111. $result = collectionTransform(new ChannelTransformer, $channels);
  112. return response()->success($result);
  113. }
  114. /**
  115. * @api {post} company/auth/officialAccounts 服务号列表
  116. * @apiVersion 1.0.0
  117. * @apiName officials
  118. * @apiGroup CompanyAuth
  119. * @apiParam {String} app_id 分配好的{app_id}
  120. * @apiParam {String} nonce_str 随机字符串
  121. * @apiParam {String} timestamp 时间戳
  122. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  123. * @apiSuccess {int} code 状态码
  124. * @apiSuccess {String} msg 信息
  125. * @apiSuccess {Object} data 结果集
  126. * @apiSuccess {Int} id 渠道ID
  127. * @apiSuccess {Int} channel_id 站点ID
  128. * @apiSuccess {String} app_id 服务号APPID
  129. * @apiSuccess {String} name 渠道名称
  130. * @apiSuccess {String} created_at 创建时间
  131. * @apiSuccess {String} sort_no 关注优先级
  132. * @apiSuccessExample {json} Success-Response:
  133. * {
  134. * "code": 0,
  135. * "msg": "",
  136. * "data": [
  137. * {
  138. * "app_id": '',
  139. * "channel_id": 130,
  140. * "name": "半烟溪桥",
  141. * "created_at": "2018-01-06 10:38:36"
  142. * }
  143. * ]
  144. * }
  145. */
  146. public function officialAccounts()
  147. {
  148. $service = new OfficialAccountService;
  149. $result = collectionTransform(new OfficialAccountTransformer, $service->getOfficialAccountsByChannelIds($this->channel_ids));
  150. return response()->success($result);
  151. }
  152. /**
  153. * @api {post} company/auth/orders 订单
  154. * @apiVersion 1.0.0
  155. * @apiName orders
  156. * @apiGroup CompanyAuth
  157. * @apiParam {String} channel_id 站点id
  158. * @apiParam {String} status 支付状态 PAID:已支付, UNPAID: 未支付
  159. * @apiParam {String} begin_date 开始时间(时间区间小于60天,格式yyyy-MM-dd HH:mm:ss)
  160. * @apiParam {String} end_date 截止时间(时间区间小于60天,格式yyyy-MM-dd HH:mm:ss)
  161. * @apiParam {Int} page 分页页码
  162. * @apiParam {String} app_id 分配好的{app_id}
  163. * @apiParam {String} nonce_str 随机字符串
  164. * @apiParam {String} timestamp 时间戳
  165. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  166. * @apiSuccess {int} code 状态码
  167. * @apiSuccess {String} msg 信息
  168. * @apiSuccess {Object} data 结果集
  169. * @apiSuccess {Object} list 数据结果
  170. * @apiSuccess {Object} meta 分页信息
  171. * @apiSuccess {Int} total 分页总数
  172. * @apiSuccess {Int} uid 用户UID
  173. * @apiSuccess {Object} price 充值金额
  174. * @apiSuccess {String} trade_no 订单号
  175. * @apiSuccess {String} status 支付状态 PAID:已支付, UNPAID: 未支付
  176. * @apiSuccess {String} created_at 创建时间
  177. * @apiSuccess {String} pay_end_at 支付时间
  178. * @apiSuccess {Int} send_order_id 派单ID
  179. * @apiSuccess {String} send_order_name 派单名称
  180. * @apiSuccess {String} promotion_url 派单链接
  181. * @apiSuccess {String} activity_name 活动名称
  182. * @apiSuccess {String} keyword 关键词
  183. * @apiSuccess {Int} user_charge_times 充值次数
  184. * @apiSuccess {String} bid 书号
  185. * @apiSuccess {String} book_name 书名
  186. * @apiSuccess {String} register_time 用户注册时间
  187. * @apiSuccess {String} subscribe_time 关注时间
  188. * @apiSuccess {String} app_id 关注app_id
  189. * @apiSuccess {String} opend_id 关注公众号的openid,只有强关了才有(公众号号是渠道授权的,用户得点击系统返回的带openid的参数的链接,访问后才算强关,或者从强关二维码进来的也算)
  190. * @apiSuccess {String} register_open_id 分销后台订单的openid(是平台系统默认的静默登录的openid)
  191. * @apiSuccess {String} wechat_name 关注公众号
  192. * @apiSuccess {String} order_type 订单类型[普通充值、包年、包月、包季]
  193. * @apiSuccess {String} push_msg_id 推送消息id,标记用[custom_开头是客服消息,template_开头是模板消息,下划线后是id]
  194. * @apiSuccess {String} ip 订单创建IP地址
  195. * @apiSuccess {Int} activity_id 活动ID
  196. * HTTP/1.1 200 OK
  197. * {
  198. * "code": 0,
  199. * "msg": "",
  200. * "data": {
  201. * "list": [
  202. * {
  203. * "uid": 162261533,
  204. * "price": 200.5,
  205. * "trade_no": "343333235sdrf",
  206. * "status": "PAID",
  207. * "created_at": "2019-12-24 11:43:58",
  208. * "pay_end_at": "2019-12-24 11:43:58",
  209. * "send_order_id": 1,
  210. * "send_order_name": "1",
  211. * "activity_name": "",
  212. * "keyword": "",
  213. * "user_charge_times": 1,
  214. * "push_msg_id": "custom_4041988",
  215. * "ip": "36.18.52.247",
  216. * "activity_id": 2522,
  217. * }
  218. * ],
  219. * "meta": {
  220. * "total": 1,
  221. * "per_page": 100,
  222. * "current_page": 1,
  223. * "total": 1,
  224. * "next_page_url": "",
  225. * "prev_page_url": ""
  226. * }
  227. * }
  228. * }
  229. */
  230. public function orders(ChannelQueryRequest $request)
  231. {
  232. $channel_id = $request->get('channel_id');
  233. $status = $request->get('status');
  234. $begin_date = $request->get('begin_date', date('Y-m-d', strtotime('-7 days')));
  235. $end_date = $request->get('end_date', date('Y-m-d', strtotime('+1 days')));
  236. if (strtotime($end_date) - strtotime($begin_date) > SysConsts::ONE_DAY_SECONDS * 60) {
  237. return response()->error('COMPANY_AUTH_OVER_TIME');
  238. } else {
  239. $service = new OrderService;
  240. $result = $service->companyAuthOrders(compact('channel_id', 'status', 'begin_date', 'end_date'));
  241. return response()->pagination(new OrderTransformer, $result);
  242. }
  243. }
  244. /**
  245. * 添加书币
  246. * @apiVersion 1.0.0
  247. * @apiName addBookCoin
  248. * @apiGroup CompanyAuth
  249. * @apiParam {String} channel_id 站点id
  250. * @apiParam {String} uid 用户ID
  251. * @apiParam {String} openid 用户openid
  252. * @apiParam {String} amount 书币
  253. * @apiParam {String} app_id 分配好的{app_id}
  254. * @apiParam {String} nonce_str 随机字符串
  255. * @apiParam {String} timestamp 时间戳
  256. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  257. * @apiSuccess {int} code 状态码
  258. * @apiSuccess {String} msg 信息
  259. * @apiSuccess {Object} data 结果集
  260. * HTTP/1.1 200 OK
  261. * {
  262. * "code": 0,
  263. * "msg": "",
  264. * "data": {
  265. * "success": 1
  266. * }
  267. * }
  268. */
  269. public function addBookCoin(ChannelQueryRequest $request)
  270. {
  271. $channel_id = $request->get('channel_id');
  272. $uid = $request->get('uid');
  273. $openid = $request->get('openid');
  274. $amount = (int)$request->get('amount');
  275. $limit_amount = 2000;
  276. // 参数判断
  277. if ((empty($openid) && empty($uid)) || empty($channel_id) || empty($amount) || $amount < 0 || $amount > $limit_amount) {
  278. return response()->json(['code'=>-1, 'msg'=>'传参有误!']);
  279. }
  280. // 获取当前用户信息
  281. $user_info = '';
  282. if (!empty($uid)) {
  283. $user_info = $prev_coin = DB::connection('mysql')->table('users')->where(['id'=>$uid, 'distribution_channel_id'=>$channel_id])
  284. ->select('id', 'distribution_channel_id', 'balance', 'reward_balance')->first();
  285. }else if(!empty($openid)) {
  286. $user_info = $prev_coin = DB::connection('mysql')->table('users')
  287. ->where(['distribution_channel_id'=>$channel_id, 'openid'=>$openid])
  288. ->select('id', 'distribution_channel_id', 'balance', 'reward_balance')->first();
  289. }
  290. $user_info = (array)$user_info;
  291. if (!$user_info) return response()->json(['code'=>-1, 'msg'=>'用户不存在!']);
  292. // 当日该站点该用户获得的总书币
  293. $sum = DB::connection('mysql')->table('user_coin_logs')->where(['distribution_channel_id'=>$channel_id, 'uid'=>$user_info['id'], 'day'=>date('Y-m-d')])->sum('amount');
  294. if ($sum + $amount > $limit_amount) {
  295. return response()->json(['code' => -1, 'msg' => '每个用户每个站点每日加书币的总额不得超过'.$limit_amount.'!']);
  296. }
  297. try {
  298. DB::connection('mysql')->beginTransaction();
  299. $result = DB::connection('mysql')->table('users')->where(['id'=>$user_info['id']])->update([
  300. 'balance' => $user_info['balance'] + $amount,
  301. 'reward_balance' => $user_info['reward_balance'] + $amount,
  302. ]);
  303. if (!$result) {
  304. DB::connection('mysql')->rollback();
  305. return response()->json(['code'=>-1, 'msg'=>'数据库异常!']);
  306. }
  307. $boolen = DB::connection('mysql')->table('user_coin_logs')->insert([
  308. 'distribution_channel_id' => $user_info['distribution_channel_id'],
  309. 'uid' => $user_info['id'],
  310. 'day' => date('Y-m-d'),
  311. 'before' => $user_info['balance'],
  312. 'amount' => $amount,
  313. 'after' => $user_info['balance'] + $amount,
  314. 'created_at' => date('Y-m-d H:i:s'),
  315. 'updated_at' => date('Y-m-d H:i:s'),
  316. ]);
  317. if (!$boolen) {
  318. DB::connection('mysql')->rollback();
  319. return response()->json(['code'=>-1, 'msg'=>'数据库异常!']);
  320. }
  321. DB::connection('mysql')->commit();
  322. }catch(\Exception $e) {
  323. DB::connection('mysql')->rollback();
  324. return response()->json(['code'=>-1, 'msg'=>$e->getMessage()]);
  325. }
  326. return response()->json(['code'=>1, 'msg'=>'', 'data'=>['success' => 1]]);
  327. }
  328. /**
  329. * 添加书币或会员有效期
  330. * @apiVersion 1.0.0
  331. * @apiName addBookCoinV2
  332. * @apiGroup CompanyAuth
  333. * @apiParam {String} channel_id 站点id
  334. * @apiParam {String} uid 用户ID
  335. * @apiParam {String} openid 用户openid
  336. * @apiParam {String} type 类型(coin: 加书币 day: 加会员有效期,单位: 天)
  337. * @apiParam {String} [amount] 书币(type类型为coin时必填)
  338. * @apiParam {String} [day] 书币(type类型为day时必填)
  339. * @apiParam {String} app_id 分配好的{app_id}
  340. * @apiParam {String} nonce_str 随机字符串
  341. * @apiParam {String} timestamp 时间戳
  342. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  343. * @apiSuccess {int} code 状态码
  344. * @apiSuccess {String} msg 信息
  345. * @apiSuccess {Object} data 结果集
  346. * HTTP/1.1 200 OK
  347. * {
  348. * "code": 0,
  349. * "msg": "",
  350. * "data": {
  351. * "success": 1
  352. * }
  353. * }
  354. */
  355. public function addBookCoinV2(ChannelQueryRequest $request)
  356. {
  357. $channel_id = $request->get('channel_id');
  358. $uid = $request->get('uid');
  359. $openid = $request->get('openid');
  360. $amount = (int)$request->get('amount');
  361. $type = $request->get('type');
  362. $day = $request->get('day');
  363. $limit_amount = 2000;
  364. $limit_users = 20;
  365. // 参数判断
  366. if ((empty($openid) && empty($uid)) || empty($channel_id) || empty($type) || !in_array($type, ['coin', 'day'])) {
  367. return response()->json(['code'=>-1, 'msg'=>'传参有误!']);
  368. }
  369. if ($type == 'coin' && (empty($amount) || $amount < 0 || $amount > $limit_amount)) return response()->json(['code'=>-1, 'msg'=>'传参有误!']);
  370. if ($type == 'day' && (empty($day) || $day < 0 || $day > 366)) return response()->json(['code'=>-1, 'msg'=>'传参有误!']);
  371. // 获取当前用户信息
  372. $user_info = '';
  373. if (!empty($uid)) {
  374. $user_info = $prev_coin = DB::connection('mysql')->table('users')->where(['id'=>$uid, 'distribution_channel_id'=>$channel_id])
  375. ->select('id', 'distribution_channel_id', 'balance', 'reward_balance')->first();
  376. }else if(!empty($openid)) {
  377. $user_info = $prev_coin = DB::connection('mysql')->table('users')
  378. ->where(['distribution_channel_id'=>$channel_id, 'openid'=>$openid])
  379. ->select('id', 'distribution_channel_id', 'balance', 'reward_balance')->first();
  380. }
  381. $user_info = (array)$user_info;
  382. if (!$user_info) return response()->json(['code'=>-1, 'msg'=>'用户不存在!']);
  383. if ($type == 'day') { // 加包时日期
  384. $year_order = DB::connection('mysql')->table('year_orders')->where(['distribution_channel_id'=>$channel_id, 'uid'=>$user_info['id']])->select('id', 'end_time')->first();
  385. try {
  386. DB::connection('mysql')->beginTransaction();
  387. if ($year_order) {
  388. $year_order = (array)$year_order;
  389. $before_end_time = $year_order['end_time'];
  390. $after_end_time = date('Y-m-d H:i:s', (strtotime($before_end_time) + $day * 86400));
  391. $result = DB::connection('mysql')->table('year_orders')->where(['id'=>$year_order['id']])->update([
  392. 'end_time' => $after_end_time,
  393. 'updated_at' => date('Y-m-d H:i:s')
  394. ]);
  395. }else {
  396. $before_end_time = date('Y-m-d H:i:s');
  397. $after_end_time = date('Y-m-d H:i:s', (time() + $day * 86400));
  398. $result = DB::connection('mysql')->table('year_orders')->insert([
  399. 'uid' => $user_info['id'],
  400. 'begin_time' => $before_end_time,
  401. 'end_time' => $after_end_time,
  402. 'distribution_channel_id' => $channel_id,
  403. 'send_order_id' => 0,
  404. 'created_at' => date('Y-m-d H:i:s'),
  405. 'updated_at' => date('Y-m-d H:i:s'),
  406. ]);
  407. }
  408. if (!$result) {
  409. DB::connection('mysql')->rollback();
  410. return response()->json(['code'=>-1, 'msg'=>'数据库异常!']);
  411. }
  412. $boolen = DB::connection('mysql')->table('user_coin_logs')->insert([
  413. 'distribution_channel_id' => $user_info['distribution_channel_id'],
  414. 'uid' => $user_info['id'],
  415. 'day' => date('Y-m-d'),
  416. 'before_end_time' => $before_end_time,
  417. 'day_num' => $day,
  418. 'after_end_time' => $after_end_time,
  419. 'type' => 2,
  420. 'created_at' => date('Y-m-d H:i:s'),
  421. 'updated_at' => date('Y-m-d H:i:s'),
  422. ]);
  423. if (!$boolen) {
  424. DB::connection('mysql')->rollback();
  425. return response()->json(['code'=>-1, 'msg'=>'数据库异常!']);
  426. }
  427. DB::connection('mysql')->commit();
  428. }catch(\Exception $e) {
  429. DB::connection('mysql')->rollback();
  430. return response()->json(['code'=>-1, 'msg'=>$e->getMessage()]);
  431. }
  432. return response()->json(['code'=>1, 'msg'=>'', 'data'=>['success' => 1]]);
  433. }else { // 加书币
  434. // 当日该站点该用户获得的总书币
  435. $sum = DB::connection('mysql')->table('user_coin_logs')->where(['distribution_channel_id'=>$channel_id, 'uid'=>$user_info['id'], 'day'=>date('Y-m-d')])->sum('amount');
  436. if ($sum + $amount > $limit_amount) {
  437. return response()->json(['code' => -1, 'msg' => '每个用户每个站点每日加书币的总额不得超过'.$limit_amount.'!']);
  438. }
  439. // 当日该站点加过书币的总用户数
  440. $today_users = DB::connection('mysql')->table('user_coin_logs')->where(['distribution_channel_id'=>$channel_id, 'day'=>date('Y-m-d')])->groupBy(['uid'])->get()->pluck('uid')->toArray();
  441. if (count($today_users) > $limit_users) return response()->json(['code' => -1, 'msg' => '每个站点每日加书币的用户数不得超过'.$limit_users.'!']);
  442. if (count($today_users) == $limit_users && !in_array($uid, $today_users)) return response()->json(['code' => -1, 'msg' => '每个站点每日加书币的用户数不得超过'.$limit_users.'!']);
  443. try {
  444. DB::connection('mysql')->beginTransaction();
  445. $result = DB::connection('mysql')->table('users')->where(['id'=>$user_info['id']])->update([
  446. 'balance' => $user_info['balance'] + $amount,
  447. 'reward_balance' => $user_info['reward_balance'] + $amount,
  448. ]);
  449. if (!$result) {
  450. DB::connection('mysql')->rollback();
  451. return response()->json(['code'=>-1, 'msg'=>'数据库异常!']);
  452. }
  453. $boolen = DB::connection('mysql')->table('user_coin_logs')->insert([
  454. 'distribution_channel_id' => $user_info['distribution_channel_id'],
  455. 'uid' => $user_info['id'],
  456. 'day' => date('Y-m-d'),
  457. 'before' => $user_info['balance'],
  458. 'amount' => $amount,
  459. 'after' => $user_info['balance'] + $amount,
  460. 'created_at' => date('Y-m-d H:i:s'),
  461. 'updated_at' => date('Y-m-d H:i:s'),
  462. ]);
  463. if (!$boolen) {
  464. DB::connection('mysql')->rollback();
  465. return response()->json(['code'=>-1, 'msg'=>'数据库异常!']);
  466. }
  467. DB::connection('mysql')->commit();
  468. }catch(\Exception $e) {
  469. DB::connection('mysql')->rollback();
  470. return response()->json(['code'=>-1, 'msg'=>$e->getMessage()]);
  471. }
  472. return response()->json(['code'=>1, 'msg'=>'', 'data'=>['success' => 1]]);
  473. }
  474. }
  475. /**
  476. * @api {post} company/auth/sendOrders 派单信息列表
  477. * @apiVersion 1.0.0
  478. * @apiName sendOrders
  479. * @apiGroup CompanyAuth
  480. * @apiParam {String} channel_id 站点id
  481. * @apiParam {String} begin_date 开始时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)
  482. * @apiParam {String} end_date 截止时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)
  483. * @apiParam {Int} page 分页页码
  484. * @apiParam {String} app_id 分配好的{app_id}
  485. * @apiParam {String} nonce_str 随机字符串
  486. * @apiParam {String} timestamp 时间戳
  487. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  488. * @apiSuccess {int} code 状态码
  489. * @apiSuccess {String} msg 信息
  490. * @apiSuccess {Object} data 结果集
  491. * @apiSuccess {Object} list 数据结果
  492. * @apiSuccess {Object} meta 分页信息
  493. * @apiSuccess {Int} total 分页总数
  494. * @apiSuccess {Int} id 派单ID
  495. * @apiSuccess {Int} channel_id 渠道ID
  496. * @apiSuccess {String} name 派单名称
  497. * @apiSuccess {Int} registerNum 注册用户数
  498. * @apiSuccess {Int} chapter_id 推广章节ID
  499. * @apiSuccess {String} chapter_name 推广章节
  500. * @apiSuccess {String} subscribe_chapter_name 强关章节
  501. * @apiSuccess {Int} totalChargeAmount 充值金额
  502. * @apiSuccess {Int} fansNum 关注用户数
  503. * @apiSuccess {Decimal} cost 成本
  504. * @apiSuccess {Int} payUserNum 付费用户数
  505. * @apiSuccess {Int} UV UV
  506. * @apiSuccess {Int} PV PV
  507. * @apiSuccess {String} promotion_url 推广链接
  508. * @apiSuccess {String} created_at 创建时间
  509. * @apiSuccessExample {json} Success-Response:
  510. * {
  511. * "code": 0,
  512. * "msg": "",
  513. * "data": {
  514. * "list": [
  515. * {
  516. * "id": 915338,
  517. * "channel_id": 166,
  518. * "name": "qqq",
  519. * "registerNum": 0,
  520. * "chapter_name": "第二章 断子绝孙",
  521. * "subscribe_chapter_name": "第一章 出嫁",
  522. * "totalChargeAmount": 0,
  523. * "fansNum": 0,
  524. * "cost": "0.00",
  525. * "payUserNum": 0,
  526. * "PV": 0,
  527. * "UV": 0,
  528. * "promotion_url": "https://siteJKa6oWBEzR7Y5Dp8.localhost/yun/915338",
  529. * "created_at":''
  530. * }
  531. * ],
  532. * "meta": {
  533. * "total": 1,
  534. * "per_page": 100,
  535. * "current_page": 1,
  536. * "last_page": 1,
  537. * "next_page_url": "",
  538. * "prev_page_url": ""
  539. * }
  540. * }
  541. * }
  542. */
  543. public function sendOrders(ChannelQueryRequest $request)
  544. {
  545. $channel_id = $request->get('channel_id', 0);
  546. $begin_date = $request->get('begin_date', date('Y-m-d', strtotime('-7 days')));
  547. $end_date = $request->get('end_date', date('Y-m-d', strtotime('+1 days')));
  548. if (strtotime($end_date) - strtotime($begin_date) > SysConsts::ONE_DAY_SECONDS * 31) {
  549. return response()->error('COMPANY_AUTH_OVER_TIME');
  550. } else {
  551. $service = new SendOrderService;
  552. $result = $service->companyAuthSendOrders(compact('channel_id', 'begin_date', 'end_date'));
  553. $result = (new SendOrderStatistic(collect($result->items())->pluck('id')->all()))->getDataList($result);
  554. return response()->pagination(new SendOrderTransformer, $result);
  555. }
  556. }
  557. /**
  558. * @api {post} company/auth/sendOrder 派单明细
  559. * @apiVersion 1.0.0
  560. * @apiName sendOrder
  561. * @apiGroup CompanyAuth
  562. * @apiParam {String} app_id 分配好的{app_id}
  563. * @apiParam {Int} send_order_id 派单ID
  564. * @apiParam {String} nonce_str 随机字符串
  565. * @apiParam {String} timestamp 时间戳
  566. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  567. * @apiError {int} code 状态码
  568. * @apiError {String} msg 信息
  569. * @apiSuccess {int} code 状态码
  570. * @apiSuccess {String} msg 信息
  571. * @apiSuccess {Object} data 结果集
  572. * @apiSuccess {String} send_order_name 渠道名称
  573. * @apiSuccess {Int} distribution_channel_id 渠道ID
  574. * @apiSuccess {String} bid 书号
  575. * @apiSuccess {String} book_name 书名
  576. * @apiSuccess {Int} cid 章节ID
  577. * @apiSuccessExample {json} Success-Response:
  578. * HTTP/1.1 200 OK
  579. * {
  580. * "code": 0,
  581. * "msg": "",
  582. * "data": {
  583. * "send_order_name": "知音书苑-0315-1-张艳",
  584. * "distribution_channel_id": 8,
  585. * "bid": "5pNo6A7wqQmB1WgQygDjkOM9VZn2vXeY",
  586. * "book_name": "一生只求一个你"
  587. * }
  588. * }
  589. */
  590. public function findSendOrder(SingleSendOrderRequest $request)
  591. {
  592. $send_order_id = $request->get('send_order_id');
  593. $service = new SendOrderService;
  594. $send_order = $service->findSendOrderByChannels($send_order_id, $this->channel_ids);
  595. if ($send_order) {
  596. return response()->success([
  597. 'send_order_name' => $send_order->name,
  598. 'distribution_channel_id' => $send_order->distribution_channel_id,
  599. 'bid' => book_hash_encode($send_order->book_id),
  600. 'book_name' => $send_order->book_name,
  601. 'cid' => $send_order->chapter_id,
  602. ]);
  603. } else {
  604. return response()->error('COMPANY_AUTH_EMPTY');
  605. }
  606. }
  607. /**
  608. * @api {post} company/auth/dayStatistic 订单日统计数据
  609. * @apiVersion 1.0.0
  610. * @apiName dayStatistic
  611. * @apiGroup CompanyAuth
  612. * @apiParam {String} channel_id 站点id
  613. * @apiParam {String} begin_date 开始时间(时间区间小于30天,格式yyyy-MM-dd)
  614. * @apiParam {String} end_date 截止时间(时间区间小于30天,格式yyyy-MM-dd)
  615. * @apiParam {Int} page 分页页码
  616. * @apiParam {String} app_id 分配好的{app_id}
  617. * @apiParam {String} nonce_str 随机字符串
  618. * @apiParam {String} timestamp 时间戳
  619. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  620. * @apiSuccess {int} code 状态码
  621. * @apiSuccess {String} msg 信息
  622. * @apiSuccess {Object} data 结果集
  623. * @apiSuccess {Object} list 数据结果
  624. * @apiSuccess {Object} meta 分页信息
  625. * @apiSuccess {Int} total 分页总数
  626. * @apiSuccess {String} date 日期
  627. * @apiSuccess {Int} channel_id 渠道ID
  628. * @apiSuccess {Int} pay_number 总付费用户数
  629. * @apiSuccess {Int} charge_amount 总充值金额
  630. * @apiSuccess {Int} first_pay_number 首充用户数
  631. * @apiSuccess {Int} first_charge_amount 首充充值金额
  632. * @apiSuccess {Int} read_uv 阅读人数
  633. * @apiSuccess {Int} register_number 注册用户数
  634. * @apiSuccess {Int} register_pay_number 当日注册用户首充用户数
  635. * @apiSuccess {Int} register_charge_amount 当日注册用户首充金额
  636. * @apiSuccessExample {json} Success-Response:
  637. * {
  638. * "code": 0,
  639. * "msg": "",
  640. * "data": {
  641. * "list": [
  642. * {
  643. * "date": "2020-02-26",
  644. * "channel_id": 5,
  645. * "pay_number": 283,
  646. * "charge_amount": "11123.11",
  647. * "first_pay_number": 233,
  648. * "first_charge_amount": "8013.20",
  649. * "read_uv": 3598,
  650. * "register_number": 1669,
  651. * "register_pay_number": 201,
  652. * "register_charge_amount": "6861.00"
  653. * }
  654. * ],
  655. * "meta": {
  656. * "total": 1,
  657. * "per_page": 100,
  658. * "current_page": 1,
  659. * "last_page": 1,
  660. * "next_page_url": "",
  661. * "prev_page_url": ""
  662. * }
  663. * }
  664. * }
  665. */
  666. public function dayStatistic(ChannelQueryRequest $request)
  667. {
  668. $channel_id = $request->get('channel_id', 0);
  669. $begin_date = $request->get('begin_date', date('Y-m-d', strtotime('-7 days')));
  670. $end_date = $request->get('end_date', date('Y-m-d'));
  671. $service = new OrderService;
  672. $result = $service->companyAuthDayStatistic(compact('channel_id', 'begin_date', 'end_date'));
  673. return response()->pagination(new OrderDayStatsTransformer, $result);
  674. }
  675. /**
  676. * @api {post} company/auth/chapters/free 免费章节列表
  677. * @apiVersion 1.0.0
  678. * @apiName freeChapters
  679. * @apiGroup CompanyAuth
  680. * @apiParam {String} app_id 分配好的{app_id}
  681. * @apiParam {String} bid 书号
  682. * @apiParam {String} nonce_str 随机字符串
  683. * @apiParam {String} timestamp 时间戳
  684. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  685. * @apiSuccess {int} code 状态码
  686. * @apiSuccess {String} msg 信息
  687. * @apiSuccess {Object} data 结果集
  688. * @apiSuccess {Int} id 章节ID
  689. * @apiSuccess {Int} next_cid 下一章章节ID
  690. * @apiSuccess {String} content 章节内容
  691. * @apiSuccess {String} name 章节名称
  692. * @apiSuccessExample {json} Success-Response:
  693. * HTTP/1.1 200 OK
  694. * {
  695. * "code": 0,
  696. * "msg": "",
  697. * "data": [
  698. * {
  699. * "id": 1,
  700. * "name": "第1章 初相见",
  701. * "next_cid": 1253,
  702. * "content": "",
  703. * },
  704. * {
  705. * "id": 1253,
  706. * "name": "第2章 姊妹恶",
  707. * "next_cid": 1252,
  708. * "content": "",
  709. * }
  710. * ]
  711. * }
  712. */
  713. public function findBookFreeChapters(BookQueryRequest $request)
  714. {
  715. $hash_bid = $request->get('bid', '');
  716. $bid = CommonHelper::book_hash_decode($hash_bid);
  717. $service = new BookConfigService;
  718. $chapters = $service->findBookFreeChapters($bid);
  719. return response()->success($chapters);
  720. }
  721. /**
  722. * @api {post} company/auth/customMsg 客服消息列表
  723. * @apiVersion 1.0.0
  724. * @apiName customMsg
  725. * @apiGroup CompanyAuth
  726. * @apiParam {String} start_time 创建时间:开始(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
  727. * @apiParam {String} end_time 截止时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
  728. * @apiParam {String} send_start_time 发送时间:开始(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
  729. * @apiParam {String} send_end_time 截止时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
  730. * @apiParam {String} book_name 书名 可选
  731. * @apiParam {String} name 消息名称 可选
  732. * @apiParam {String} channel_id 站点
  733. * @apiParam {Int} page 分页页码
  734. * @apiParam {String} app_id 分配好的{app_id}
  735. * @apiParam {String} nonce_str 随机字符串
  736. * @apiParam {String} timestamp 时间戳
  737. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  738. * @apiSuccess {int} code 状态码
  739. * @apiSuccess {String} msg 信息
  740. * @apiSuccess {Object} data 结果集
  741. * @apiSuccess {Object} list 数据结果
  742. * @apiSuccess {Object} meta 分页信息
  743. * @apiSuccess {Int} total 分页总数
  744. * @apiSuccess {Int} id
  745. * @apiSuccess {String} appid 微信号APPID
  746. * @apiSuccess {String} name 消息名称
  747. * @apiSuccess {String} send_time 消息发送时间
  748. * @apiSuccess {Int} uv
  749. * @apiSuccess {Int} pv
  750. * @apiSuccess {Int} user_num 送达人数
  751. * @apiSuccess {Int} pay_user_num 充值用户
  752. * @apiSuccess {Decimal} charge_amount 充值金额
  753. * @apiSuccess {String} book_name 书名
  754. * @apiSuccess {String} chapter_name 章节名称
  755. * @apiSuccessExample {json} Success-Response:
  756. * HTTP/1.1 200 OK
  757. * {
  758. * "code": 0,
  759. * "msg": "",
  760. * "data": {
  761. * "list": [
  762. * {
  763. * "id": 4852,
  764. * "appid": null,
  765. * "name": "女神小说-0430-客服消息",
  766. * "send_time": "2018-04-30 14:00:00",
  767. * "uv": 0,
  768. * "pv": 0,
  769. * "channel_id": 0,
  770. * "pay_user_num": 0,
  771. * "charge_amount": "",
  772. * "book_name": "",
  773. * "chapter_name": "",
  774. * "create_at": "2018-04-30 12:40:22"
  775. * },
  776. * {
  777. * "id": 4776,
  778. * "appid": null,
  779. * "name": "女神小说-0429-客服消息",
  780. * "send_time": "2018-04-29 14:00:00",
  781. * "uv": 0,
  782. * "pv": 0,
  783. * "channel_id": 0,
  784. * "pay_user_num": 0,
  785. * "charge_amount": "",
  786. * "book_name": "",
  787. * "chapter_name": "",
  788. * "create_at": "2018-04-29 13:58:01"
  789. * },
  790. * ],
  791. * "meta": {
  792. * "total": 2,
  793. * "per_page": 15,
  794. * "current_page": 1,
  795. * "last_page": 1,
  796. * "next_page_url": "http://vipchannel.pre.aizhuishu.com/api/company/auth/customMsg?page=2",
  797. * "prev_page_url": ""
  798. * }
  799. * }
  800. * }
  801. */
  802. public function findCustomSendMsg(CustomSendMsgRequest $request)
  803. {
  804. $start_time = $request->get('start_time', date('Y-m-d', strtotime('-7 days')));
  805. $end_time = $request->get('end_time', date('Y-m-d'));
  806. $send_start_time = $request->get('send_start_time', '');
  807. $send_end_time = $request->get('send_end_time', '');
  808. $book_name = $request->get('book_name', '');
  809. $name = $request->get('name', '');
  810. $channel_id = $request->get('channel_id', '');
  811. $params = [
  812. 'start_time' => $start_time,
  813. 'end_time' => $end_time,
  814. 'book_name' => $book_name,
  815. 'name' => $name,
  816. 'channel_id' => $channel_id,
  817. 'send_start_time' => $send_start_time,
  818. 'send_end_time' => $send_end_time
  819. ];
  820. if (strtotime($end_time) - strtotime($start_time) > SysConsts::ONE_DAY_SECONDS * 31) {
  821. return response()->error('COMPANY_AUTH_OVER_TIME');
  822. }
  823. if ($send_start_time && $send_end_time && strtotime($send_start_time) - strtotime($send_end_time) > SysConsts::ONE_DAY_SECONDS * 31) {
  824. return response()->error('COMPANY_AUTH_OVER_TIME');
  825. }
  826. $result = (new OfficialAccountService)->findCustomSendMsgs($params);
  827. return response()->pagination(new CustomSendMsgsTransformers, $result);
  828. }
  829. /**
  830. * @api {post} company/auth/templateSendMsg 模板消息列表
  831. * @apiVersion 1.0.0
  832. * @apiName templateSendMsg
  833. * @apiGroup CompanyAuth
  834. * @apiParam {String} start_time 创建时间:开始(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
  835. * @apiParam {String} end_time 截止时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
  836. * @apiParam {String} send_start_time 发送时间:开始(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
  837. * @apiParam {String} send_end_time 截止时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
  838. * @apiParam {String} book_name 书名 可选
  839. * @apiParam {String} name 消息名称 可选
  840. * @apiParam {String} channel_id 站点
  841. * @apiParam {Int} page 分页页码
  842. * @apiParam {String} app_id 分配好的{app_id}
  843. * @apiParam {String} nonce_str 随机字符串
  844. * @apiParam {String} timestamp 时间戳
  845. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  846. * @apiSuccess {int} code 状态码
  847. * @apiSuccess {String} msg 信息
  848. * @apiSuccess {Object} data 结果集
  849. * @apiSuccess {Object} list 数据结果
  850. * @apiSuccess {Object} meta 分页信息
  851. * @apiSuccess {Int} total 分页总数
  852. * @apiSuccess {Int} id
  853. * @apiSuccess {String} appid 微信号APPID
  854. * @apiSuccess {String} name 消息名称
  855. * @apiSuccess {String} send_time 消息发送时间
  856. * @apiSuccess {Int} uv
  857. * @apiSuccess {Int} pv
  858. * @apiSuccess {Int} user_num 送达人数
  859. * @apiSuccess {Int} pay_user_num 充值用户
  860. * @apiSuccess {Decimal} charge_amount 充值金额
  861. * @apiSuccess {String} book_name 书名
  862. * @apiSuccess {String} chapter_name 章节名称
  863. * @apiSuccessExample {json} Success-Response:
  864. * HTTP/1.1 200 OK
  865. * {
  866. * "code": 0,
  867. * "msg": "",
  868. * "data": {
  869. * "list": [
  870. * {
  871. * "id": 4852,
  872. * "appid": null,
  873. * "name": "女神小说-0430-客服消息",
  874. * "send_time": "2018-04-30 14:00:00",
  875. * "uv": 0,
  876. * "pv": 0,
  877. * "channel_id": 0,
  878. * "pay_user_num": 0,
  879. * "charge_amount": "",
  880. * "book_name": "",
  881. * "chapter_name": "",
  882. * "create_at": "2018-04-30 12:40:22"
  883. * },
  884. * {
  885. * "id": 4776,
  886. * "appid": null,
  887. * "name": "女神小说-0429-客服消息",
  888. * "send_time": "2018-04-29 14:00:00",
  889. * "uv": 0,
  890. * "pv": 0,
  891. * "channel_id": 0,
  892. * "pay_user_num": 0,
  893. * "charge_amount": "",
  894. * "book_name": "",
  895. * "chapter_name": "",
  896. * "create_at": "2018-04-29 13:58:01"
  897. * },
  898. * ],
  899. * "meta": {
  900. * "total": 2,
  901. * "per_page": 15,
  902. * "current_page": 1,
  903. * "last_page": 1,
  904. * "next_page_url": "http://vipchannel.pre.aizhuishu.com/api/company/auth/customMsg?page=2",
  905. * "prev_page_url": ""
  906. * }
  907. * }
  908. * }
  909. */
  910. public function findTemplateSendMsg(CustomSendMsgRequest $request)
  911. {
  912. $start_time = $request->get('start_time', date('Y-m-d', strtotime('-7 days')));
  913. $end_time = $request->get('end_time', date('Y-m-d'));
  914. $send_start_time = $request->get('send_start_time', '');
  915. $send_end_time = $request->get('send_end_time', '');
  916. $book_name = $request->get('book_name', '');
  917. $name = $request->get('name', '');
  918. $channel_id = $request->get('channel_id', '');
  919. $params = [
  920. 'start_time' => $start_time,
  921. 'end_time' => $end_time,
  922. 'book_name' => $book_name,
  923. 'name' => $name,
  924. 'channel_id' => $channel_id,
  925. 'send_start_time' => $send_start_time,
  926. 'send_end_time' => $send_end_time
  927. ];
  928. if (strtotime($end_time) - strtotime($start_time) > SysConsts::ONE_DAY_SECONDS * 31) {
  929. return response()->error('COMPANY_AUTH_OVER_TIME');
  930. }
  931. if ($send_start_time && $send_end_time && strtotime($send_start_time) - strtotime($send_end_time) > SysConsts::ONE_DAY_SECONDS * 31) {
  932. return response()->error('COMPANY_AUTH_OVER_TIME');
  933. }
  934. $result = (new OfficialAccountService)->findWechatTemplateMsgs($params);
  935. return response()->pagination(new CustomSendMsgsTransformers, $result);
  936. }
  937. /**
  938. * @api {post} company/auth/delayMsg 延时客服消息
  939. * @apiVersion 1.0.0
  940. * @apiName delayMsg
  941. * @apiGroup CompanyAuth
  942. * @apiParam {String} channel_id 站点
  943. * @apiParam {Int} page 分页页码
  944. * @apiParam {String} app_id 分配好的{app_id}
  945. * @apiParam {String} nonce_str 随机字符串
  946. * @apiParam {String} timestamp 时间戳
  947. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  948. * @apiSuccess {int} code 状态码
  949. * @apiSuccess {String} msg 信息
  950. * @apiSuccess {Object} data 结果集
  951. * @apiSuccess {Object} list 数据结果
  952. * @apiSuccess {Object} meta 分页信息
  953. * @apiSuccess {Int} total 分页总数
  954. * @apiSuccess {Int} id
  955. * @apiSuccess {String} title 标题
  956. * @apiSuccess {String} link 链接
  957. * @apiSuccess {String} desc 描述
  958. * @apiSuccess {Int} time_delay 延时时间
  959. * @apiSuccess {String} user_type 用户类型:ALL所有 UNPAID 未付费 PAID 付费用户
  960. * @apiSuccess {String} chapter_info 章节名
  961. * @apiSuccess {String} book_info 书名
  962. * @apiSuccess {String} type 消息类型 page 页面 book 小说
  963. * @apiSuccess {Int} uv
  964. * @apiSuccess {Int} pv
  965. * @apiSuccess {Int} pay_user_num 付费用户数
  966. * @apiSuccess {Decimal} charge_amount 充值金额
  967. * @apiSuccessExample {json} Success-Response:
  968. * HTTP/1.1 200 OK
  969. * {
  970. * "code": 0,
  971. * "msg": "",
  972. * "data": {
  973. * "list": [
  974. * {
  975. * "id":"",
  976. * "title":"",
  977. * "link":"",
  978. * "desc":"",
  979. * "time_delay":"",
  980. * "user_type":"",
  981. * "chapter_name":"",
  982. * "book_name":"",
  983. * "type":"",
  984. * "uv":"",
  985. * "pv":"",
  986. * "pay_user_num": "",
  987. * "charge_amount": "",
  988. * }
  989. * ],
  990. * "meta": {
  991. * "total": 1,
  992. * "per_page": 15,
  993. * "current_page": 1,
  994. * "last_page": 1,
  995. * "next_page_url": "",
  996. * "prev_page_url": ""
  997. * }
  998. * }
  999. * }
  1000. */
  1001. public function delayMsg(CustomSendMsgRequest $request)
  1002. {
  1003. $channel_id = $request->get('channel_id', '');
  1004. $params = [
  1005. 'channel_id' => $channel_id,
  1006. ];
  1007. $result = (new OfficialAccountService)->findWechatDelayMsgs($params);
  1008. return response()->pagination(new DelaySendMsgsTransformers, $result);
  1009. }
  1010. /**
  1011. * @api {post} company/auth/activity 促销活动列表
  1012. * @apiVersion 1.0.0
  1013. * @apiName activity
  1014. * @apiGroup CompanyAuth
  1015. * @apiParam {String} channel_id 站点
  1016. * @apiParam {Int} page 分页页码
  1017. * @apiParam {String} app_id 分配好的{app_id}
  1018. * @apiParam {String} nonce_str 随机字符串
  1019. * @apiParam {String} timestamp 时间戳
  1020. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  1021. * @apiSuccess {int} code 状态码
  1022. * @apiSuccess {String} msg 信息
  1023. * @apiSuccess {Object} data 结果集
  1024. * @apiSuccess {Object} list 数据结果
  1025. * @apiSuccess {Object} meta 分页信息
  1026. * @apiSuccess {Int} total 分页总数
  1027. * @apiSuccess {Int} id
  1028. * @apiSuccess {String} name 活动名称
  1029. * @apiSuccess {String} activity_page 活动地址
  1030. * @apiSuccess {String} created_at 创建时间
  1031. * @apiSuccess {String} start_time 开始时间
  1032. * @apiSuccess {String} end_time 结束时间
  1033. * @apiSuccess {Decimal} price 价格
  1034. * @apiSuccess {Int} orderCount 订单数量
  1035. * @apiSuccess {Decimal} totalChargeAmount 充值金额
  1036. * @apiSuccess {Int} successOrderCount 成功订单数
  1037. * @apiSuccess {Int} pageUserNum 访问人数
  1038. * @apiSuccess {Int} is_reader_page_show 是否阅读页展示
  1039. * @apiSuccess {Int} is_sign_message_show 是否签到页展示
  1040. * @apiSuccess {Decimal} successrate 订单成功率
  1041. * @apiSuccess {Int} is_over 是否结束
  1042. * @apiSuccessExample {json} Success-Response:
  1043. * HTTP/1.1 200 OK
  1044. * {
  1045. * "code": 0,
  1046. * "msg": "",
  1047. * "data": {
  1048. * "list": [
  1049. * {
  1050. * "id":"",
  1051. * "name":"",
  1052. * "activity_page":"",
  1053. * "created_at":"",
  1054. * "start_time":"",
  1055. * "end_time":"",
  1056. * "price":"",
  1057. * "orderCount":"",
  1058. * "totalChargeAmount":"",
  1059. * "successOrderCount":"",
  1060. * "pageUserNum":"",
  1061. * "is_reader_page_show": "",
  1062. * "is_sign_message_show": "",
  1063. * "successrate": "",
  1064. * "is_over": ""
  1065. * }
  1066. * ],
  1067. * "meta": {
  1068. * "total": 1,
  1069. * "per_page": 15,
  1070. * "current_page": 1,
  1071. * "last_page": 1,
  1072. * "next_page_url": "",
  1073. * "prev_page_url": ""
  1074. * }
  1075. * }
  1076. * }
  1077. */
  1078. public function activity(ChannelQueryRequest $request)
  1079. {
  1080. $channel_id = $request->get('channel_id', 0);
  1081. $result = (new ActivityService)->getCommonActivitiesWithStats($channel_id);
  1082. return response()->pagination(new ActivityTransformer, $result);
  1083. }
  1084. /**
  1085. * @api {post} company/auth/selfActivity 自定义活动列表
  1086. * @apiVersion 1.0.0
  1087. * @apiName selfActivity
  1088. * @apiGroup CompanyAuth
  1089. * @apiParam {String} channel_id 站点
  1090. * @apiParam {Int} page 分页页码
  1091. * @apiParam {String} app_id 分配好的{app_id}
  1092. * @apiParam {String} nonce_str 随机字符串
  1093. * @apiParam {String} timestamp 时间戳
  1094. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  1095. * @apiSuccess {int} code 状态码
  1096. * @apiSuccess {String} msg 信息
  1097. * @apiSuccess {Object} data 结果集
  1098. * @apiSuccess {Object} list 数据结果
  1099. * @apiSuccess {Object} meta 分页信息
  1100. * @apiSuccess {Int} total 分页总数
  1101. * @apiSuccess {Int} id
  1102. * @apiSuccess {String} name 活动名称
  1103. * @apiSuccess {String} activity_page 活动地址
  1104. * @apiSuccess {String} created_at 创建时间
  1105. * @apiSuccess {String} start_time 开始时间
  1106. * @apiSuccess {String} end_time 结束时间
  1107. * @apiSuccess {Decimal} price 价格
  1108. * @apiSuccess {Int} orderCount 订单数量
  1109. * @apiSuccess {Decimal} totalChargeAmount 充值金额
  1110. * @apiSuccess {Int} successOrderCount 成功订单数
  1111. * @apiSuccess {Int} pageUserNum 访问人数
  1112. * @apiSuccess {Int} is_reader_page_show 是否阅读页展示
  1113. * @apiSuccess {Int} is_sign_message_show 是否签到页展示
  1114. * @apiSuccess {Decimal} successrate 订单成功率
  1115. * @apiSuccess {Int} is_over 是否结束
  1116. * @apiSuccessExample {json} Success-Response:
  1117. * HTTP/1.1 200 OK
  1118. * {
  1119. * "code": 0,
  1120. * "msg": "",
  1121. * "data": {
  1122. * "list": [
  1123. * {
  1124. * "id":"",
  1125. * "name":"",
  1126. * "activity_page":"",
  1127. * "created_at":"",
  1128. * "start_time":"",
  1129. * "end_time":"",
  1130. * "price":"",
  1131. * "orderCount":"",
  1132. * "totalChargeAmount":"",
  1133. * "successOrderCount":"",
  1134. * "pageUserNum":"",
  1135. * "is_reader_page_show": "",
  1136. * "is_sign_message_show": "",
  1137. * "successrate": "",
  1138. * "is_over": ""
  1139. * }
  1140. * ],
  1141. * "meta": {
  1142. * "total": 1,
  1143. * "per_page": 15,
  1144. * "current_page": 1,
  1145. * "last_page": 1,
  1146. * "next_page_url": "",
  1147. * "prev_page_url": ""
  1148. * }
  1149. * }
  1150. * }
  1151. */
  1152. public function selfActivity(ChannelQueryRequest $request)
  1153. {
  1154. $channel_id = $request->get('channel_id', 0);
  1155. $result = (new ActivityService)->getChannelActivitiesWithStats($channel_id);
  1156. return response()->pagination(new ActivityTransformer, $result);
  1157. }
  1158. }