AppController.php 53 KB

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