RegisterChannel.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. namespace App\Console\Channel;
  3. use App\Libs\Utils;
  4. use Illuminate\Console\Command;
  5. use App\Services\Channel\ChannelUserService;
  6. use Illuminate\Support\Facades\DB;
  7. class RegisterChannel extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'channel:register {nickname} {account} {password} {--channel_type=}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '创建站点';
  21. private $channelUserService;
  22. public function __construct(
  23. ChannelUserService $channelUserService
  24. )
  25. {
  26. parent::__construct();
  27. $this->channelUserService = $channelUserService;
  28. }
  29. public function handle()
  30. {
  31. // 传参
  32. $nickname = trim($this->argument('nickname'));
  33. $account = trim($this->argument('account'));
  34. $password = trim($this->argument('password'));
  35. $channel_type = trim($this->option('channel_type'));
  36. if (!$nickname || !$account || !$password) {
  37. dd('参数不对,请确认后重试');
  38. }
  39. if (!$channel_type) $channel_type = 'RECHARGE';
  40. try {
  41. DB::beginTransaction();
  42. // 注册站点用户
  43. $res = $this->channelUserService->register($account, $password);
  44. $channel_user_id = DB::table('channel_users')->where('account', $account)->value('id');
  45. if (!$channel_user_id) {
  46. DB::rollBack();
  47. Utils::throwError('1002:注册站点用户失败');
  48. }
  49. // 获取下一个站点id
  50. $distribution_channel_id = DB::table('distribution_channels')->insertGetId([
  51. 'name' => $channel_type == 'RECHARGE' ? '掌维充送制' : '掌维会员制',
  52. 'channel_type' => $channel_type,
  53. 'pay_merchant_id' => 1,
  54. 'nickname' => $nickname,
  55. 'channel_user_id' => $channel_user_id,
  56. 'book_charge_type' => 'HYBRID',
  57. 'book_coin' => 1250,
  58. 'chapter_coin' => 60,
  59. 'book_calculate_price_type' => 'all',
  60. 'chapter_calculate_price_type' => 'bywords',
  61. 'created_at' => date('Y-m-d H:i:s'),
  62. 'updated_at' => date('Y-m-d H:i:s'),
  63. ]);
  64. if (!$distribution_channel_id) {
  65. DB::rollBack();
  66. Utils::throwError('1002:站点创建失败');
  67. }
  68. // 创建模板
  69. $template_id = DB::table('channel_templates')->insertGetId([
  70. 'distribution_channel_id' => $distribution_channel_id,
  71. 'template_name' => '默认模板',
  72. 'template_type' => 1,
  73. 'user_scope' => 1,
  74. 'orders' => 0,
  75. 'is_enable' => 1,
  76. 'template_cate' => $channel_type == 'RECHARGE' ? 1 : 2,
  77. 'created_at' => date('Y-m-d H:i:s'),
  78. 'updated_at' => date('Y-m-d H:i:s'),
  79. ]);
  80. if (!$template_id) {
  81. DB::rollBack();
  82. Utils::throwError('1002:默认模版创建失败');
  83. }
  84. $boolen = DB::table('distribution_channels')->where('id', $distribution_channel_id)->update([
  85. 'pay_id' => $template_id,
  86. 'updated_at' => date('Y-m-d H:i:s')
  87. ]);
  88. if (!$boolen) {
  89. DB::rollBack();
  90. Utils::throwError('1002:更新站点模板失败');
  91. }
  92. if ($channel_type == 'PERIOD') {
  93. $products = [
  94. [
  95. 'type' => 'WEEK',
  96. 'name' => '周卡',
  97. 'name_desc' => '周卡',
  98. 'price' => '9.9',
  99. 'price_desc' => '',
  100. 'angle_sign_text' => '',
  101. 'given' => 0,
  102. 'is_default' => 0,
  103. 'is_enabled' => 1,
  104. 'sequence' => 1,
  105. 'template_type' => $template_id,
  106. 'template_id' => $template_id,
  107. 'created_at' => date('Y-m-d H:i:s'),
  108. ],
  109. [
  110. 'type' => 'MONTH',
  111. 'name' => '月卡',
  112. 'name_desc' => '月卡(限时优惠)',
  113. 'price' => '18.8',
  114. 'price_desc' => '原价:¥30',
  115. 'angle_sign_text' => '',
  116. 'given' => 0,
  117. 'is_default' => 1,
  118. 'is_enabled' => 1,
  119. 'sequence' => 2,
  120. 'template_type' => $template_id,
  121. 'template_id' => $template_id,
  122. 'created_at' => date('Y-m-d H:i:s'),
  123. ],
  124. [
  125. 'type' => 'QUARTER',
  126. 'name' => '季卡',
  127. 'name_desc' => '季卡(限时优惠)',
  128. 'price' => '25',
  129. 'price_desc' => '原价:¥50',
  130. 'angle_sign_text' => '',
  131. 'given' => 0,
  132. 'is_default' => 0,
  133. 'is_enabled' => 1,
  134. 'sequence' => 3,
  135. 'template_type' => $template_id,
  136. 'template_id' => $template_id,
  137. 'created_at' => date('Y-m-d H:i:s'),
  138. ],
  139. [
  140. 'type' => 'RECHARGE',
  141. 'name' => '年卡',
  142. 'name_desc' => '年卡(限时优惠)',
  143. 'price' => '68',
  144. 'price_desc' => '原价:¥120',
  145. 'angle_sign_text' => '',
  146. 'given' => 0,
  147. 'is_default' => 0,
  148. 'is_enabled' => 1,
  149. 'sequence' => 4,
  150. 'template_type' => $template_id,
  151. 'template_id' => $template_id,
  152. 'created_at' => date('Y-m-d H:i:s'),
  153. ],
  154. ];
  155. }else {
  156. $products = [
  157. [
  158. 'type' => 'RECHARGE',
  159. 'name' => '19.9元',
  160. 'name_desc' => '',
  161. 'price' => '19.9',
  162. 'price_desc' => '',
  163. 'angle_sign_text' => '',
  164. 'given' => 0,
  165. 'is_default' => 1,
  166. 'is_enabled' => 1,
  167. 'sequence' => 1,
  168. 'template_type' => $template_id,
  169. 'template_id' => $template_id,
  170. 'created_at' => date('Y-m-d H:i:s'),
  171. ],
  172. [
  173. 'type' => 'RECHARGE',
  174. 'name' => '39.9元',
  175. 'name_desc' => '',
  176. 'price' => '39.9',
  177. 'price_desc' => '增1900书币',
  178. 'angle_sign_text' => '热',
  179. 'given' => 1900,
  180. 'is_default' => 0,
  181. 'is_enabled' => 1,
  182. 'sequence' => 2,
  183. 'template_type' => $template_id,
  184. 'template_id' => $template_id,
  185. 'created_at' => date('Y-m-d H:i:s'),
  186. ],
  187. [
  188. 'type' => 'RECHARGE',
  189. 'name' => '59.9元',
  190. 'name_desc' => '',
  191. 'price' => '59.9',
  192. 'price_desc' => '增3900书币',
  193. 'angle_sign_text' => '多送39',
  194. 'given' => 3900,
  195. 'is_default' => 0,
  196. 'is_enabled' => 1,
  197. 'sequence' => 3,
  198. 'template_type' => $template_id,
  199. 'template_id' => $template_id,
  200. 'created_at' => date('Y-m-d H:i:s'),
  201. ],
  202. [
  203. 'type' => 'WEEK',
  204. 'name' => '周卡',
  205. 'name_desc' => '周卡',
  206. 'price' => '29.9',
  207. 'price_desc' => '',
  208. 'angle_sign_text' => '一周所有书免费看',
  209. 'given' => 0,
  210. 'is_default' => 0,
  211. 'is_enabled' => 1,
  212. 'sequence' => 4,
  213. 'template_type' => $template_id,
  214. 'template_id' => $template_id,
  215. 'created_at' => date('Y-m-d H:i:s'),
  216. ],
  217. [
  218. 'type' => 'MONTH',
  219. 'name' => '月卡',
  220. 'name_desc' => '月卡',
  221. 'price' => '49.9',
  222. 'price_desc' => '',
  223. 'angle_sign_text' => '一个月所有书免费看',
  224. 'given' => 0,
  225. 'is_default' => 0,
  226. 'is_enabled' => 1,
  227. 'sequence' => 5,
  228. 'template_type' => $template_id,
  229. 'template_id' => $template_id,
  230. 'created_at' => date('Y-m-d H:i:s'),
  231. ],
  232. [
  233. 'type' => 'RECHARGE',
  234. 'name' => '年卡',
  235. 'name_desc' => '年卡',
  236. 'price' => '89.9',
  237. 'price_desc' => '',
  238. 'angle_sign_text' => '一年所有书免费看',
  239. 'given' => 0,
  240. 'is_default' => 0,
  241. 'is_enabled' => 1,
  242. 'sequence' => 6,
  243. 'template_type' => $template_id,
  244. 'template_id' => $template_id,
  245. 'created_at' => date('Y-m-d H:i:s'),
  246. ],
  247. ];
  248. }
  249. $boolen2 = DB::table('products')->insert($products);
  250. if (!$boolen2) {
  251. DB::rollBack();
  252. Utils::throwError('1002:充值档位创建失败');
  253. }
  254. }catch (\Exception $e) {
  255. DB::rollBack();
  256. dd($e->getMessage());
  257. }
  258. DB::commit();
  259. dd('创建站点成功!');
  260. }
  261. }