PayorderBusiness.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <?php
  2. namespace app\business;
  3. use Illuminate\Support\Arr;
  4. use support\Db;
  5. use support\Redis;
  6. use Throwable;
  7. use yzh52521\EasyHttp\Http;
  8. class PayorderBusiness
  9. {
  10. static private $url = "https://xswg.bbbzf.xyz/api/pay/create_order";
  11. static private $apikey = 'NAIE3F8W6AQFMMCUTWQ5TZJU2XAPZT3QW0USC274FHMYM61BUTUBC6KLMSKKNEYA623NWI1V29INBKC4NHMRTJXM4VTVDVCQK6ZXCKIXUYL6TFNCTWIHJKAYFHM3D4ZB';
  12. static private $memberid = 20000214;
  13. /**
  14. * @param array $param [
  15. * order_no
  16. * ]
  17. * @return array
  18. */
  19. static public function payment($order_no, $pay_bankcode, $money, $url = '')
  20. {
  21. if (empty($url)) {
  22. $url = getenv('WEB_HOST');
  23. }
  24. $arr = [
  25. 'mchId' => self::$memberid,
  26. 'productId' => $pay_bankcode,
  27. 'mchOrderNo' => $order_no,
  28. 'amount' => (int)bcmul($money, 100),
  29. 'notifyUrl' => getenv('API_HOST') . '/api/pay/payment_callback.html',//异步通知地址,支付成功后将支付成功消息以POST请求发送给这个网址
  30. 'subject' => '商品',
  31. 'body' => '商品描述',
  32. 'extra' => 'abcd',
  33. ];
  34. $arr['sign'] = self::payMd5sign($arr);
  35. $data = Http::post(self::$url, $arr)->array();
  36. return ['data' => $data, 'arr' => $arr];
  37. }
  38. static public function payMd5sign(array $param)
  39. {
  40. /* @对数组键进行ASCII码排序*/
  41. ksort($param);
  42. $arr = [];
  43. //将数组进行重组装
  44. foreach ($param as $k => $v) {
  45. if (!empty($v)) {
  46. $arr[] = $k . '=' . $v;
  47. }
  48. }
  49. //转换成字符串并且拼接上密钥
  50. $sign = implode('&', $arr) . '&key=' . self::$apikey;
  51. return strtoupper(md5($sign));
  52. }
  53. /** 生成订单号
  54. * @param array $param
  55. * @return int
  56. * @throws \Exception
  57. */
  58. static public function orderAdd(array $param)
  59. {
  60. try {
  61. $goods = Db::table('wa_goods')->where('id', $param['id'])->first();
  62. if (empty($goods)) {
  63. throw new \Exception('产品不存在!');
  64. }
  65. $payAisleData = Db::table('wa_pay_aisle')->where('characteristic', $param['pay_characteristic'])->first();
  66. if (empty($payAisleData)) {
  67. throw new \Exception('支付类型不存在!');
  68. }
  69. $characteristic = $payAisleData->characteristic;
  70. $pay_type = $payAisleData->type;
  71. $order_no = date('YmdHis') . mt_rand(1000, 9999);
  72. $payorderId = Db::table('wa_payorder')->insertGetId([
  73. 'goods_id' => $goods->id,
  74. 'goods_type' => $goods->type,
  75. 'user_id' => $param['user_data']['id'],
  76. 'order_no' => $order_no,
  77. 'pay_characteristic' => $characteristic,
  78. 'pay_type' => $pay_type,
  79. 'money' => bcmul($goods->pay_price, $param['num'], 2),
  80. 'num' => $param['num'],
  81. 'name' => Arr::get($param, 'name', null),
  82. 'mobile' => Arr::get($param, 'mobile', null),
  83. 'number' => Arr::get($param, 'number', null),
  84. 'address' => Arr::get($param, 'address', null),
  85. 'created_at' => date('Y-m-d H:i:s'),
  86. 'updated_at' => date('Y-m-d H:i:s'),
  87. ]);
  88. } catch (\Throwable $exception) {
  89. throw new \Exception($exception->getMessage());
  90. }
  91. return $payorderId;
  92. }
  93. /** 开通银行卡生成订单号
  94. * @param array $param
  95. * @return int
  96. * @throws \Exception
  97. */
  98. static public function CardorderAdd(array $param)
  99. {
  100. try {
  101. $goods = Db::table('wa_goods')->where('id', $param['id'])->first();
  102. if (empty($goods)) {
  103. throw new \Exception('产品不存在!');
  104. }
  105. $price_money = bcmul($goods->pay_price, $param['num']);
  106. if ($param['user_data']['money_one'] < $price_money) {
  107. throw new \Exception('华润财富余额不足!');
  108. }
  109. $payorderId = Db::table('wa_payorder')->insertGetId([
  110. 'goods_id' => $goods->id,
  111. 'goods_type' => $goods->type,
  112. 'user_id' => $param['user_data']['id'],
  113. 'order_no' => date('YmdHis') . mt_rand(1000, 9999),
  114. 'pay_characteristic' => 0,
  115. 'pay_type' => 0,
  116. 'is_pay' => 2,
  117. 'money' => $price_money,
  118. 'num' => 1,
  119. 'created_at' => date('Y-m-d H:i:s'),
  120. 'updated_at' => date('Y-m-d H:i:s'),
  121. ]);
  122. } catch (\Throwable $exception) {
  123. throw new \Exception($exception->getMessage());
  124. }
  125. return $payorderId;
  126. }
  127. /**提现
  128. * @return void
  129. */
  130. static public function tx_withdraw($param, $service_charge = '')
  131. {
  132. try {
  133. $payAisleData = Db::table('wa_pay_aisle')->where('characteristic', $param['pay_characteristic'])->first();
  134. if (empty($payAisleData)) {
  135. throw new \Exception('支付类型不存在!');
  136. }
  137. $payorderId = Db::table('wa_payorder')->insertGetId([
  138. 'goods_type' => 1001,
  139. 'user_id' => $param['user_data']['id'],
  140. 'order_no' => date('YmdHis') . mt_rand(1000, 9999),
  141. 'pay_characteristic' => $payAisleData->characteristic,
  142. 'pay_type' => $payAisleData->type,
  143. 'money' => bcmul($param['money'], $service_charge, 2),
  144. 'withdraw_money' => $param['money'],
  145. 'mold_type' => $param['mold'],
  146. 'created_at' => date('Y-m-d H:i:s'),
  147. 'updated_at' => date('Y-m-d H:i:s'),
  148. ]);
  149. } catch (\Throwable $exception) {
  150. throw new \Exception($exception->getMessage());
  151. }
  152. return $payorderId;
  153. }
  154. /** 购买原始股
  155. * @param $num
  156. * @param $user_id
  157. * @param $pay_characteristic
  158. * @return int
  159. * @throws \Exception
  160. */
  161. static public function orderAddInitialShare($num, $user_id, $pay_characteristic)
  162. {
  163. try {
  164. $wa_system = Db::table('wa_system')->first();
  165. $payAisleData = Db::table('wa_pay_aisle')->where('characteristic', $pay_characteristic)->first();
  166. if (empty($payAisleData)) {
  167. throw new \Exception('支付类型不存在!');
  168. }
  169. $payorderId = Db::table('wa_payorder')->insertGetId([
  170. 'goods_id' => 0,
  171. 'goods_type' => 10,
  172. 'user_id' => $user_id,
  173. 'order_no' => date('YmdHis') . mt_rand(1000, 9999),
  174. 'pay_characteristic' => $payAisleData->characteristic,
  175. 'pay_type' => $payAisleData->type,
  176. 'money' => bcmul($wa_system->money_five_value, $num, 2),
  177. 'num' => $num,
  178. 'created_at' => date('Y-m-d H:i:s'),
  179. 'updated_at' => date('Y-m-d H:i:s'),
  180. ]);
  181. } catch (\Throwable $exception) {
  182. throw new \Exception($exception->getMessage());
  183. }
  184. return $payorderId;
  185. }
  186. /** 提现回调
  187. * @param $data
  188. * @return void
  189. * @throws \Exception
  190. */
  191. static public function payorderJkjtx($data)
  192. {
  193. try {
  194. /** @var $bankCard 银行卡 */
  195. $bankCard = Db::table('wa_bank_card')->where('uid', $data['user_id'])->first();
  196. $withdrawId = Db::table('wa_withdraw')->insertGetId([
  197. 'order_no' => date('YmdHis') . mt_rand(10000, 99999),
  198. 'user_id' => $data['user_id'],
  199. 'money' => $data['withdraw_money'],
  200. 'type' => $data['mold_type'],
  201. 'affiliated_bank' => $bankCard->affiliated_bank,
  202. 'account_holder' => $bankCard->account_holder,
  203. 'card_number' => $bankCard->card_number,
  204. 'created_at' => date('Y-m-d H:i:s'),
  205. 'updated_at' => date('Y-m-d H:i:s'),
  206. ]);
  207. StreamBusiness::delStream($data['user_id'], $data['withdraw_money'], streamType4, $data['mold_type'], moldTypefild($data['mold_type']), $withdrawId);
  208. } catch (Throwable $exception) {
  209. throw new \Exception($exception->getMessage());
  210. }
  211. }
  212. /** 支付回调
  213. * @param $orderNo
  214. * @return void
  215. */
  216. static public function paymentCallback($orderNo)
  217. {
  218. try {
  219. $payorder = Db::table('wa_payorder')->where('order_no', $orderNo)->first();
  220. if ($payorder->is_pay != 1) {
  221. throw new \Exception('订单已处理!');
  222. }
  223. self::payorderSave(collect($payorder)->toArray());
  224. } catch (\Throwable $exception) {
  225. throw new \Exception($exception->getMessage());
  226. }
  227. return true;
  228. }
  229. /** 购买原始股权回调
  230. * @param $data
  231. * @return void
  232. */
  233. // static public function goodsStockRights($data)
  234. // {
  235. // try {
  236. // $goodsData=Db::table('wa_goods')->where('id',$data['goods_id'])->first();
  237. // $thisDay=date('Y-m-d H:i:s');
  238. // /** @var $futureDay 未来时间*/
  239. // $futureDay=futureDay(1095);
  240. //
  241. // $myGoodsId=Db::table('wa_my_goods')->insertGetId([
  242. // 'user_id' => $data['user_id'],
  243. // 'goods_id' => $goodsData->id,
  244. // 'money' => $data['money'],
  245. // 'on' => date('YmdHis').mt_rand(1000,9999),
  246. // 'type' => $goodsData->type,
  247. // 'pay_id' => $data['id'],
  248. // 'stock_rights' => $goodsData->stock_rights,
  249. // 'unit_price' => $goodsData->unit_price,
  250. // 'refund_amount' => $data['money'],
  251. // 'expiretime' => strtotime($futureDay),
  252. // 'expiredate' => $futureDay,
  253. // 'created_at' => $thisDay,
  254. // 'updated_at' => $thisDay
  255. // ]);
  256. //
  257. //
  258. //// StreamBusiness::addStream($data['user_id'],bcmul($goodsData->stock_rights,$goodsData->unit_price,2),streamType5,moldType4,moldTypefild(moldType4),$data['id']);
  259. //
  260. // $usersData=Db::table('wa_users')->where('id',$data['user_id'])->first();
  261. // $system=Db::table('wa_system')->first();
  262. // if(!empty($usersData->pid) && !empty($system->rebate)){
  263. // StreamBusiness::addStream($usersData->pid,$system->rebate,streamType10,moldType4,moldTypefild4,$data['id']);
  264. // }
  265. // if(!empty($usersData->ppid) && !empty($system->rebate_one)){
  266. // StreamBusiness::addStream($usersData->ppid,$system->rebate_one,streamType10,moldType4,moldTypefild4,$data['id']);
  267. // }
  268. //
  269. // if(!empty($usersData->toppid) && !empty($system->rebate_two)){
  270. // StreamBusiness::addStream($usersData->toppid,$system->rebate_two,streamType10,moldType4,moldTypefild4,$data['id']);
  271. // }
  272. //
  273. // /** 新增消费数据 */
  274. // Db::table('wa_users')->where('id',$data['user_id'])->increment('invest_money',$data['money']);
  275. //
  276. // Db::table('wa_goods')->where('id',$goodsData->id)->decrement('num',1);
  277. //
  278. // }catch (\Throwable $exception){
  279. // throw new \Exception($exception->getMessage());
  280. // }
  281. // }
  282. /** 订单回调处理
  283. * @param $data 订单信息
  284. * @return void
  285. */
  286. static public function payorderSave($data)
  287. {
  288. try {
  289. self::payorderGoods($data);
  290. Db::table('wa_payorder')->where('id', $data['id'])->update([
  291. 'is_pay' => 2,
  292. 'updated_at' => date('Y-m-d H:i:s'),
  293. ]);
  294. } catch (\Throwable $exception) {
  295. throw new \Exception($exception->getMessage());
  296. }
  297. return true;
  298. }
  299. /** 商品回调
  300. * @param $data
  301. * @return void
  302. * @throws \Exception
  303. */
  304. static public function payorderGoods($data)
  305. {
  306. try {
  307. $goodsData = Db::table('wa_goods')->where('id', $data['goods_id'])->first();
  308. $thisDay = date('Y-m-d H:i:s');
  309. /** @var $futureDay 未来时间 */
  310. $futureDay = futureDay(1095);
  311. $myGoodsId = Db::table('wa_my_goods')->insertGetId([
  312. 'user_id' => $data['user_id'],
  313. 'goods_id' => $goodsData->id,
  314. 'money' => $data['money'],
  315. 'num' => $data['num'],
  316. 'on' => date('YmdHis') . mt_rand(1000, 9999),
  317. 'type' => $goodsData->type,
  318. 'pay_id' => $data['id'],
  319. 'bonus' => $goodsData->bonus,
  320. 'balance' => $goodsData->balance,
  321. 'usd_quota' => $goodsData->usd_quota,
  322. 'refund_amount' => $data['money'],
  323. 'name' => Arr::get($data, 'name', null),
  324. 'mobile' => Arr::get($data, 'mobile', null),
  325. 'number' => Arr::get($data, 'number', null),
  326. 'address' => Arr::get($data, 'address', null),
  327. 'expiretime' => strtotime($futureDay),
  328. 'expiredate' => $futureDay,
  329. 'created_at' => $thisDay,
  330. 'updated_at' => $thisDay,
  331. ]);
  332. $userlist = Db::table('wa_users')->where('id', $data['user_id'])->first();
  333. if ($goodsData->type == 1) {
  334. if (!empty($goodsData->bonus)) {
  335. Db::table('wa_cron_task')->insert([
  336. 'user_id' => $data['user_id'],
  337. 'goods_id' => $goodsData->id,
  338. 'order_id' => $data['id'],
  339. 'money' => $data['money'],
  340. 'bonus' => $goodsData->bonus,
  341. 'rebate' => $goodsData->rebate,
  342. 'rebate_one' => $goodsData->rebate_one,
  343. 'rebate_two' => $goodsData->rebate_two,
  344. 'goods_type' => $goodsData->type,
  345. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:10:00'),
  346. 'dividend_time' => strtotime($futureDay),
  347. 'created_at' => $thisDay,
  348. 'updated_at' => $thisDay,
  349. 'my_good_id' => $myGoodsId,
  350. ]);
  351. StreamBusiness::addStream($data['user_id'], $goodsData->bonus, streamType9, moldType7, moldTypefild7, $data['id']);
  352. if (!empty($userlist->pid) && !empty($goodsData->rebate)) {
  353. StreamBusiness::addStream($userlist->pid, $goodsData->rebate, streamType9, moldType9, moldTypefild9, $data['id']);
  354. }
  355. if (!empty($userlist->ppid) && !empty($goodsData->rebate_one)) {
  356. StreamBusiness::addStream($userlist->ppid, $goodsData->rebate_one, streamType9, moldType9, moldTypefild9, $data['id']);
  357. }
  358. if (!empty($userlist->toppid) && !empty($goodsData->rebate_two)) {
  359. StreamBusiness::addStream($userlist->toppid, $goodsData->rebate_two, streamType9, moldType9, moldTypefild9, $data['id']);
  360. }
  361. }
  362. if (!empty($goodsData->trial_bonus)) {
  363. $carkdatalist = Db::table('wa_user_social_cark')
  364. ->where('user_id', $data['user_id'])
  365. ->where('status', 3)->first();
  366. if (!empty($carkdatalist)) {
  367. StreamBusiness::addStream($data['user_id'], $goodsData->trial_bonus, streamType9, moldType6, moldTypefild6, $data['id']);
  368. }
  369. }
  370. if (!empty($goodsData->balance)) {
  371. StreamBusiness::addStream($data['user_id'], $goodsData->balance, streamType9, moldType10, moldTypefild10, $data['id']);
  372. StreamBusiness::delStream($data['user_id'], $goodsData->balance, streamType25, moldType3, moldTypefild3, $data['id']);
  373. }
  374. StreamBusiness::delStream($data['user_id'], $goodsData->payment_usd, streamType21, moldType3, moldTypefild3, $data['id']);
  375. /** 分佣 */
  376. $system = Db::table('wa_system')->first();
  377. if (!empty($userlist->pid) && !empty($system->rebate)) {
  378. StreamBusiness::addStream($userlist->pid, bcmul($goodsData->pay_price, bcdiv($system->rebate, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  379. }
  380. if (!empty($userlist->ppid) && !empty($system->rebate_one)) {
  381. StreamBusiness::addStream($userlist->ppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_one, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  382. }
  383. if (!empty($userlist->toppid) && !empty($system->rebate_two)) {
  384. StreamBusiness::addStream($userlist->toppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_two, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  385. }
  386. } elseif ($goodsData->type == 2) {
  387. if (!empty($goodsData->bonus)) {
  388. Db::table('wa_cron_task')->insert([
  389. 'user_id' => $data['user_id'],
  390. 'goods_id' => $goodsData->id,
  391. 'order_id' => $data['id'],
  392. 'money' => $data['money'],
  393. 'bonus' => $goodsData->bonus,
  394. 'balance' => $goodsData->balance,
  395. 'rebate' => $goodsData->rebate,
  396. 'rebate_one' => $goodsData->rebate_one,
  397. 'rebate_two' => $goodsData->rebate_two,
  398. 'goods_type' => $goodsData->type,
  399. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:10:00'),
  400. 'dividend_time' => strtotime($futureDay),
  401. 'created_at' => $thisDay,
  402. 'updated_at' => $thisDay,
  403. 'my_good_id' => $myGoodsId,
  404. 'event_time' => 0,
  405. 'is_activity' => 0,
  406. ]);
  407. StreamBusiness::addStream($data['user_id'], $goodsData->bonus, streamType26, moldType11, moldTypefild11, $data['id']);
  408. }
  409. if (!empty($goodsData->balance)) {
  410. StreamBusiness::addStream($data['user_id'], $goodsData->balance, streamType30, moldType10, moldTypefild10, $data['id']);
  411. StreamBusiness::delStream($data['user_id'], $goodsData->balance, streamType27, moldType3, moldTypefild3, $data['id']);
  412. }
  413. StreamBusiness::delStream($data['user_id'], $goodsData->payment_usd, streamType28, moldType3, moldTypefild3, $data['id']);
  414. /** 分佣 */
  415. $system = Db::table('wa_system')->first();
  416. if (!empty($userlist->pid) && !empty($system->rebate)) {
  417. StreamBusiness::addStream($userlist->pid, bcmul($goodsData->pay_price, bcdiv($system->rebate, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  418. }
  419. if (!empty($userlist->ppid) && !empty($system->rebate_one)) {
  420. StreamBusiness::addStream($userlist->ppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_one, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  421. }
  422. if (!empty($userlist->toppid) && !empty($system->rebate_two)) {
  423. StreamBusiness::addStream($userlist->toppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_two, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  424. }
  425. } elseif ($goodsData->type == 3) {
  426. Db::table('wa_user_social_cark')->where('user_id', $data['user_id'])->update(['is_buy' => 2, 'buy_time' => date('Y-m-d H:i:s')]);
  427. } elseif ($goodsData->type == 4) {
  428. if (!empty($goodsData->bonus)) {
  429. Db::table('wa_cron_task_four')->insert([
  430. 'user_id' => $data['user_id'],
  431. 'goods_id' => $goodsData->id,
  432. 'order_id' => $data['id'],
  433. 'money' => $data['money'],
  434. 'bonus' => $goodsData->bonus,
  435. 'goods_type' => $goodsData->type,
  436. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:00:00'),
  437. 'dividend_time' => strtotime($futureDay),
  438. 'created_at' => $thisDay,
  439. 'updated_at' => $thisDay,
  440. 'my_good_id' => $myGoodsId,
  441. 'event_time' => 0,
  442. 'is_activity' => 0,
  443. ]);
  444. StreamBusiness::addStream($data['user_id'], $goodsData->bonus, streamType37, moldType12, moldTypefild12, $data['id']);
  445. }
  446. if (!empty($goodsData->balance)) {
  447. StreamBusiness::addStream($data['user_id'], $goodsData->balance, streamType36, moldType13, moldTypefild13, $data['id']);
  448. Db::table('wa_users')->where('id', $data['user_id'])->increment('accumulate_thirteen', $goodsData->balance);
  449. }
  450. if (!empty($goodsData->usd_quota)) {
  451. StreamBusiness::addStream($data['user_id'], $goodsData->usd_quota, streamType36, moldType14, moldTypefild14, $data['id']);
  452. Db::table('wa_users')->where('id', $data['user_id'])->increment('accumulate_fourteen', $goodsData->usd_quota);
  453. }
  454. if (!empty($goodsData->ranking)) {
  455. $cardlist = Db::table('wa_user_social_cark')->where('user_id', $data['user_id'])->first();
  456. if (!empty($cardlist)) {
  457. if ($cardlist->ranking > $goodsData->ranking) {
  458. Db::table('wa_user_social_cark')->where('id', $cardlist->id)->decrement('ranking', $goodsData->ranking);
  459. Db::table('wa_my_goods')->where('id', $myGoodsId)->update([
  460. 'ranking' => $goodsData->ranking,
  461. ]);
  462. $new_ranking = bcsub($cardlist->ranking, $goodsData->ranking);
  463. Db::table('wa_users')->where('id', $data['user_id'])->increment('increase_ranking',$goodsData->ranking);
  464. }else{
  465. $new_ranking = $cardlist->ranking;
  466. }
  467. Db::table('wa_users')->where('id', $data['user_id'])->update(['new_ranking'=> $new_ranking]);
  468. }
  469. }
  470. /** 分佣 */
  471. $system = Db::table('wa_system')->first();
  472. if (!empty($userlist->pid) && !empty($system->rebate)) {
  473. StreamBusiness::addStream($userlist->pid, bcmul($goodsData->pay_price, bcdiv($system->rebate, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  474. }
  475. if (!empty($userlist->ppid) && !empty($system->rebate_one)) {
  476. StreamBusiness::addStream($userlist->ppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_one, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  477. }
  478. if (!empty($userlist->toppid) && !empty($system->rebate_two)) {
  479. StreamBusiness::addStream($userlist->toppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_two, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  480. }
  481. }elseif ($goodsData->type == 5) {
  482. $futureDay = futureDay($goodsData->day);
  483. if (!empty($goodsData->bonus)) {
  484. Db::table('wa_cron_task')->insert([
  485. 'user_id' => $data['user_id'],
  486. 'goods_id' => $goodsData->id,
  487. 'order_id' => $data['id'],
  488. 'money' => $data['money'],
  489. 'bonus' => $goodsData->bonus,
  490. 'balance' => $goodsData->balance,
  491. 'rebate' => $goodsData->rebate,
  492. 'rebate_one' => $goodsData->rebate_one,
  493. 'rebate_two' => $goodsData->rebate_two,
  494. 'goods_type' => $goodsData->type,
  495. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:10:00'),
  496. 'dividend_time' => strtotime($futureDay),
  497. 'created_at' => $thisDay,
  498. 'updated_at' => $thisDay,
  499. 'my_good_id' => $myGoodsId,
  500. 'event_time' => 0,
  501. 'is_activity' => 0,
  502. ]);
  503. StreamBusiness::addStream($data['user_id'], $goodsData->bonus, streamType43, moldType15, moldTypefild15, $data['id']);
  504. }
  505. if (!empty($goodsData->balance)) {
  506. StreamBusiness::addStream($data['user_id'], $goodsData->balance, streamType43, moldType3, moldTypefild3, $data['id']);
  507. }
  508. Db::table('wa_users')->where('id', $data['user_id'])->update(['mailing_date'=>futureDay($goodsData->mailing_date)]);
  509. /** 分佣 */
  510. $system = Db::table('wa_system')->first();
  511. if (!empty($userlist->pid) && !empty($system->rebate)) {
  512. StreamBusiness::addStream($userlist->pid, bcmul($goodsData->pay_price, bcdiv($system->rebate, 100, 2), 2), streamType42, moldType16, moldTypefild16, $data['id']);
  513. }
  514. if (!empty($userlist->ppid) && !empty($system->rebate_one)) {
  515. StreamBusiness::addStream($userlist->ppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_one, 100, 2), 2), streamType42, moldType16, moldTypefild16, $data['id']);
  516. }
  517. if (!empty($userlist->toppid) && !empty($system->rebate_two)) {
  518. StreamBusiness::addStream($userlist->toppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_two, 100, 2), 2), streamType42, moldType16, moldTypefild16, $data['id']);
  519. }
  520. }
  521. /** 新增消费数据 */
  522. Db::table('wa_users')->where('id', $data['user_id'])->increment('invest_money', $data['money']);
  523. Db::table('wa_goods')->where('id', $goodsData->id)->decrement('num', $data['num']);
  524. } catch (\Throwable $exception) {
  525. throw new \Exception($exception->getMessage());
  526. }
  527. }
  528. }