PayorderBusiness.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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. 'affiliated_bank' => Arr::get($param, 'affiliated_bank', null),
  86. 'card_number' => Arr::get($param, 'card_number', null),
  87. 'created_at' => date('Y-m-d H:i:s'),
  88. 'updated_at' => date('Y-m-d H:i:s'),
  89. ]);
  90. } catch (\Throwable $exception) {
  91. throw new \Exception($exception->getMessage());
  92. }
  93. return $payorderId;
  94. }
  95. /** 开通银行卡生成订单号
  96. * @param array $param
  97. * @return int
  98. * @throws \Exception
  99. */
  100. static public function CardorderAdd(array $param)
  101. {
  102. try {
  103. $goods = Db::table('wa_goods')->where('id', $param['id'])->first();
  104. if (empty($goods)) {
  105. throw new \Exception('产品不存在!');
  106. }
  107. $price_money = bcmul($goods->pay_price, $param['num']);
  108. if ($param['user_data']['money_one'] < $price_money) {
  109. throw new \Exception('华润财富余额不足!');
  110. }
  111. $payorderId = Db::table('wa_payorder')->insertGetId([
  112. 'goods_id' => $goods->id,
  113. 'goods_type' => $goods->type,
  114. 'user_id' => $param['user_data']['id'],
  115. 'order_no' => date('YmdHis') . mt_rand(1000, 9999),
  116. 'pay_characteristic' => 0,
  117. 'pay_type' => 0,
  118. 'is_pay' => 2,
  119. 'money' => $price_money,
  120. 'num' => 1,
  121. 'created_at' => date('Y-m-d H:i:s'),
  122. 'updated_at' => date('Y-m-d H:i:s'),
  123. ]);
  124. } catch (\Throwable $exception) {
  125. throw new \Exception($exception->getMessage());
  126. }
  127. return $payorderId;
  128. }
  129. /**提现
  130. * @return void
  131. */
  132. static public function tx_withdraw($param, $service_charge = '')
  133. {
  134. try {
  135. $payAisleData = Db::table('wa_pay_aisle')->where('characteristic', $param['pay_characteristic'])->first();
  136. if (empty($payAisleData)) {
  137. throw new \Exception('支付类型不存在!');
  138. }
  139. $payorderId = Db::table('wa_payorder')->insertGetId([
  140. 'goods_type' => 1001,
  141. 'user_id' => $param['user_data']['id'],
  142. 'order_no' => date('YmdHis') . mt_rand(1000, 9999),
  143. 'pay_characteristic' => $payAisleData->characteristic,
  144. 'pay_type' => $payAisleData->type,
  145. 'money' => bcmul($param['money'], $service_charge, 2),
  146. 'withdraw_money' => $param['money'],
  147. 'mold_type' => $param['mold'],
  148. 'created_at' => date('Y-m-d H:i:s'),
  149. 'updated_at' => date('Y-m-d H:i:s'),
  150. ]);
  151. } catch (\Throwable $exception) {
  152. throw new \Exception($exception->getMessage());
  153. }
  154. return $payorderId;
  155. }
  156. /** 购买原始股
  157. * @param $num
  158. * @param $user_id
  159. * @param $pay_characteristic
  160. * @return int
  161. * @throws \Exception
  162. */
  163. static public function orderAddInitialShare($num, $user_id, $pay_characteristic)
  164. {
  165. try {
  166. $wa_system = Db::table('wa_system')->first();
  167. $payAisleData = Db::table('wa_pay_aisle')->where('characteristic', $pay_characteristic)->first();
  168. if (empty($payAisleData)) {
  169. throw new \Exception('支付类型不存在!');
  170. }
  171. $payorderId = Db::table('wa_payorder')->insertGetId([
  172. 'goods_id' => 0,
  173. 'goods_type' => 10,
  174. 'user_id' => $user_id,
  175. 'order_no' => date('YmdHis') . mt_rand(1000, 9999),
  176. 'pay_characteristic' => $payAisleData->characteristic,
  177. 'pay_type' => $payAisleData->type,
  178. 'money' => bcmul($wa_system->money_five_value, $num, 2),
  179. 'num' => $num,
  180. 'created_at' => date('Y-m-d H:i:s'),
  181. 'updated_at' => date('Y-m-d H:i:s'),
  182. ]);
  183. } catch (\Throwable $exception) {
  184. throw new \Exception($exception->getMessage());
  185. }
  186. return $payorderId;
  187. }
  188. /** 提现回调
  189. * @param $data
  190. * @return void
  191. * @throws \Exception
  192. */
  193. static public function payorderJkjtx($data)
  194. {
  195. try {
  196. /** @var $bankCard 银行卡 */
  197. $bankCard = Db::table('wa_bank_card')->where('uid', $data['user_id'])->first();
  198. $withdrawId = Db::table('wa_withdraw')->insertGetId([
  199. 'order_no' => date('YmdHis') . mt_rand(10000, 99999),
  200. 'user_id' => $data['user_id'],
  201. 'money' => $data['withdraw_money'],
  202. 'type' => $data['mold_type'],
  203. 'affiliated_bank' => $bankCard->affiliated_bank,
  204. 'account_holder' => $bankCard->account_holder,
  205. 'card_number' => $bankCard->card_number,
  206. 'created_at' => date('Y-m-d H:i:s'),
  207. 'updated_at' => date('Y-m-d H:i:s'),
  208. ]);
  209. StreamBusiness::delStream($data['user_id'], $data['withdraw_money'], streamType4, $data['mold_type'], moldTypefild($data['mold_type']), $withdrawId);
  210. } catch (Throwable $exception) {
  211. throw new \Exception($exception->getMessage());
  212. }
  213. }
  214. /** 支付回调
  215. * @param $orderNo
  216. * @return void
  217. */
  218. static public function paymentCallback($orderNo)
  219. {
  220. try {
  221. $payorder = Db::table('wa_payorder')->where('order_no', $orderNo)->first();
  222. if ($payorder->is_pay != 1) {
  223. throw new \Exception('订单已处理!');
  224. }
  225. self::payorderSave(collect($payorder)->toArray());
  226. } catch (\Throwable $exception) {
  227. throw new \Exception($exception->getMessage());
  228. }
  229. return true;
  230. }
  231. /** 购买原始股权回调
  232. * @param $data
  233. * @return void
  234. */
  235. // static public function goodsStockRights($data)
  236. // {
  237. // try {
  238. // $goodsData=Db::table('wa_goods')->where('id',$data['goods_id'])->first();
  239. // $thisDay=date('Y-m-d H:i:s');
  240. // /** @var $futureDay 未来时间*/
  241. // $futureDay=futureDay(1095);
  242. //
  243. // $myGoodsId=Db::table('wa_my_goods')->insertGetId([
  244. // 'user_id' => $data['user_id'],
  245. // 'goods_id' => $goodsData->id,
  246. // 'money' => $data['money'],
  247. // 'on' => date('YmdHis').mt_rand(1000,9999),
  248. // 'type' => $goodsData->type,
  249. // 'pay_id' => $data['id'],
  250. // 'stock_rights' => $goodsData->stock_rights,
  251. // 'unit_price' => $goodsData->unit_price,
  252. // 'refund_amount' => $data['money'],
  253. // 'expiretime' => strtotime($futureDay),
  254. // 'expiredate' => $futureDay,
  255. // 'created_at' => $thisDay,
  256. // 'updated_at' => $thisDay
  257. // ]);
  258. //
  259. //
  260. //// StreamBusiness::addStream($data['user_id'],bcmul($goodsData->stock_rights,$goodsData->unit_price,2),streamType5,moldType4,moldTypefild(moldType4),$data['id']);
  261. //
  262. // $usersData=Db::table('wa_users')->where('id',$data['user_id'])->first();
  263. // $system=Db::table('wa_system')->first();
  264. // if(!empty($usersData->pid) && !empty($system->rebate)){
  265. // StreamBusiness::addStream($usersData->pid,$system->rebate,streamType10,moldType4,moldTypefild4,$data['id']);
  266. // }
  267. // if(!empty($usersData->ppid) && !empty($system->rebate_one)){
  268. // StreamBusiness::addStream($usersData->ppid,$system->rebate_one,streamType10,moldType4,moldTypefild4,$data['id']);
  269. // }
  270. //
  271. // if(!empty($usersData->toppid) && !empty($system->rebate_two)){
  272. // StreamBusiness::addStream($usersData->toppid,$system->rebate_two,streamType10,moldType4,moldTypefild4,$data['id']);
  273. // }
  274. //
  275. // /** 新增消费数据 */
  276. // Db::table('wa_users')->where('id',$data['user_id'])->increment('invest_money',$data['money']);
  277. //
  278. // Db::table('wa_goods')->where('id',$goodsData->id)->decrement('num',1);
  279. //
  280. // }catch (\Throwable $exception){
  281. // throw new \Exception($exception->getMessage());
  282. // }
  283. // }
  284. /** 订单回调处理
  285. * @param $data 订单信息
  286. * @return void
  287. */
  288. static public function payorderSave($data)
  289. {
  290. try {
  291. self::payorderGoods($data);
  292. Db::table('wa_payorder')->where('id', $data['id'])->update([
  293. 'is_pay' => 2,
  294. 'updated_at' => date('Y-m-d H:i:s'),
  295. ]);
  296. } catch (\Throwable $exception) {
  297. throw new \Exception($exception->getMessage());
  298. }
  299. return true;
  300. }
  301. /** 商品回调
  302. * @param $data
  303. * @return void
  304. * @throws \Exception
  305. */
  306. static public function payorderGoods($data)
  307. {
  308. try {
  309. $goodsData = Db::table('wa_goods')->where('id', $data['goods_id'])->first();
  310. $thisDay = date('Y-m-d H:i:s');
  311. /** @var $futureDay 未来时间 */
  312. $futureDay = futureDay(1095);
  313. if ($goodsData->type == 10) {
  314. $mygoodslist = Db::table('wa_my_goods')
  315. ->where('user_id', $data['user_id'])
  316. ->where('goods_id', $goodsData->id)
  317. ->first();
  318. if ($mygoodslist) {
  319. Db::table('wa_my_goods')->where('id', $mygoodslist->id)->increment('balance', $goodsData->balance);
  320. } else {
  321. $myGoodsId = Db::table('wa_my_goods')->insertGetId([
  322. 'user_id' => $data['user_id'],
  323. 'goods_id' => $goodsData->id,
  324. 'money' => $data['money'],
  325. 'num' => $data['num'],
  326. 'on' => date('YmdHis') . mt_rand(1000, 9999),
  327. 'type' => $goodsData->type,
  328. 'pay_id' => $data['id'],
  329. 'bonus' => $goodsData->bonus,
  330. 'balance' => $goodsData->balance,
  331. 'usd_quota' => $goodsData->usd_quota,
  332. 'refund_amount' => $data['money'],
  333. 'name' => Arr::get($data, 'name', null),
  334. 'mobile' => Arr::get($data, 'mobile', null),
  335. 'number' => Arr::get($data, 'number', null),
  336. 'address' => Arr::get($data, 'address', null),
  337. 'affiliated_bank' => Arr::get($data, 'affiliated_bank', null),
  338. 'card_number' => Arr::get($data, 'card_number', null),
  339. 'expiretime' => strtotime($futureDay),
  340. 'expiredate' => $futureDay,
  341. 'created_at' => $thisDay,
  342. 'updated_at' => $thisDay,
  343. ]);
  344. }
  345. } else {
  346. $myGoodsId = Db::table('wa_my_goods')->insertGetId([
  347. 'user_id' => $data['user_id'],
  348. 'goods_id' => $goodsData->id,
  349. 'money' => $data['money'],
  350. 'num' => $data['num'],
  351. 'on' => date('YmdHis') . mt_rand(1000, 9999),
  352. 'type' => $goodsData->type,
  353. 'pay_id' => $data['id'],
  354. 'bonus' => $goodsData->bonus,
  355. 'balance' => $goodsData->balance,
  356. 'usd_quota' => $goodsData->usd_quota,
  357. 'refund_amount' => $data['money'],
  358. 'name' => Arr::get($data, 'name', null),
  359. 'mobile' => Arr::get($data, 'mobile', null),
  360. 'number' => Arr::get($data, 'number', null),
  361. 'address' => Arr::get($data, 'address', null),
  362. 'expiretime' => strtotime($futureDay),
  363. 'expiredate' => $futureDay,
  364. 'created_at' => $thisDay,
  365. 'updated_at' => $thisDay,
  366. ]);
  367. }
  368. $userlist = Db::table('wa_users')->where('id', $data['user_id'])->first();
  369. if ($goodsData->type == 1) {
  370. if (!empty($goodsData->bonus)) {
  371. Db::table('wa_cron_task')->insert([
  372. 'user_id' => $data['user_id'],
  373. 'goods_id' => $goodsData->id,
  374. 'order_id' => $data['id'],
  375. 'money' => $data['money'],
  376. 'bonus' => $goodsData->bonus,
  377. 'rebate' => $goodsData->rebate,
  378. 'rebate_one' => $goodsData->rebate_one,
  379. 'rebate_two' => $goodsData->rebate_two,
  380. 'goods_type' => $goodsData->type,
  381. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:10:00'),
  382. 'dividend_time' => strtotime($futureDay),
  383. 'created_at' => $thisDay,
  384. 'updated_at' => $thisDay,
  385. 'my_good_id' => $myGoodsId,
  386. ]);
  387. StreamBusiness::addStream($data['user_id'], $goodsData->bonus, streamType9, moldType23, moldTypefild23, $data['id']);
  388. if (!empty($userlist->pid) && !empty($goodsData->rebate)) {
  389. StreamBusiness::addStream($userlist->pid, $goodsData->rebate, streamType9, moldType9, moldTypefild9, $data['id']);
  390. }
  391. if (!empty($userlist->ppid) && !empty($goodsData->rebate_one)) {
  392. StreamBusiness::addStream($userlist->ppid, $goodsData->rebate_one, streamType9, moldType9, moldTypefild9, $data['id']);
  393. }
  394. if (!empty($userlist->toppid) && !empty($goodsData->rebate_two)) {
  395. StreamBusiness::addStream($userlist->toppid, $goodsData->rebate_two, streamType9, moldType9, moldTypefild9, $data['id']);
  396. }
  397. }
  398. if (!empty($goodsData->trial_bonus)) {
  399. $carkdatalist = Db::table('wa_user_social_cark')
  400. ->where('user_id', $data['user_id'])
  401. ->where('status', 3)->first();
  402. if (!empty($carkdatalist)) {
  403. StreamBusiness::addStream($data['user_id'], $goodsData->trial_bonus, streamType9, moldType6, moldTypefild6, $data['id']);
  404. }
  405. }
  406. if (!empty($goodsData->balance)) {
  407. StreamBusiness::addStream($data['user_id'], $goodsData->balance, streamType9, moldType10, moldTypefild10, $data['id']);
  408. StreamBusiness::delStream($data['user_id'], $goodsData->balance, streamType25, moldType3, moldTypefild3, $data['id']);
  409. }
  410. StreamBusiness::delStream($data['user_id'], $goodsData->payment_usd, streamType21, moldType3, moldTypefild3, $data['id']);
  411. /** 分佣 */
  412. $system = Db::table('wa_system')->first();
  413. if (!empty($userlist->pid) && !empty($system->rebate)) {
  414. StreamBusiness::addStream($userlist->pid, bcmul($goodsData->pay_price, bcdiv($system->rebate, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  415. }
  416. if (!empty($userlist->ppid) && !empty($system->rebate_one)) {
  417. StreamBusiness::addStream($userlist->ppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_one, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  418. }
  419. if (!empty($userlist->toppid) && !empty($system->rebate_two)) {
  420. StreamBusiness::addStream($userlist->toppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_two, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  421. }
  422. } elseif ($goodsData->type == 2) {
  423. if (!empty($goodsData->bonus)) {
  424. Db::table('wa_cron_task')->insert([
  425. 'user_id' => $data['user_id'],
  426. 'goods_id' => $goodsData->id,
  427. 'order_id' => $data['id'],
  428. 'money' => $data['money'],
  429. 'bonus' => $goodsData->bonus,
  430. 'balance' => $goodsData->balance,
  431. 'rebate' => $goodsData->rebate,
  432. 'rebate_one' => $goodsData->rebate_one,
  433. 'rebate_two' => $goodsData->rebate_two,
  434. 'goods_type' => $goodsData->type,
  435. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:10:00'),
  436. 'dividend_time' => strtotime($futureDay),
  437. 'created_at' => $thisDay,
  438. 'updated_at' => $thisDay,
  439. 'my_good_id' => $myGoodsId,
  440. 'event_time' => 0,
  441. 'is_activity' => 0,
  442. ]);
  443. StreamBusiness::addStream($data['user_id'], $goodsData->bonus, streamType26, moldType11, moldTypefild11, $data['id']);
  444. }
  445. if (!empty($goodsData->balance)) {
  446. StreamBusiness::addStream($data['user_id'], $goodsData->balance, streamType30, moldType10, moldTypefild10, $data['id']);
  447. StreamBusiness::delStream($data['user_id'], $goodsData->balance, streamType27, moldType3, moldTypefild3, $data['id']);
  448. }
  449. StreamBusiness::delStream($data['user_id'], $goodsData->payment_usd, streamType28, moldType3, moldTypefild3, $data['id']);
  450. /** 分佣 */
  451. $system = Db::table('wa_system')->first();
  452. if (!empty($userlist->pid) && !empty($system->rebate)) {
  453. StreamBusiness::addStream($userlist->pid, bcmul($goodsData->pay_price, bcdiv($system->rebate, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  454. }
  455. if (!empty($userlist->ppid) && !empty($system->rebate_one)) {
  456. StreamBusiness::addStream($userlist->ppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_one, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  457. }
  458. if (!empty($userlist->toppid) && !empty($system->rebate_two)) {
  459. StreamBusiness::addStream($userlist->toppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_two, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  460. }
  461. } elseif ($goodsData->type == 3) {
  462. 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')]);
  463. } elseif ($goodsData->type == 4) {
  464. if (!empty($goodsData->bonus)) {
  465. Db::table('wa_cron_task_four')->insert([
  466. 'user_id' => $data['user_id'],
  467. 'goods_id' => $goodsData->id,
  468. 'order_id' => $data['id'],
  469. 'money' => $data['money'],
  470. 'bonus' => $goodsData->bonus,
  471. 'goods_type' => $goodsData->type,
  472. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:00:00'),
  473. 'dividend_time' => strtotime($futureDay),
  474. 'created_at' => $thisDay,
  475. 'updated_at' => $thisDay,
  476. 'my_good_id' => $myGoodsId,
  477. 'event_time' => 0,
  478. 'is_activity' => 0,
  479. ]);
  480. StreamBusiness::addStream($data['user_id'], $goodsData->bonus, streamType37, moldType12, moldTypefild12, $data['id']);
  481. }
  482. if (!empty($goodsData->balance)) {
  483. StreamBusiness::addStream($data['user_id'], $goodsData->balance, streamType36, moldType13, moldTypefild13, $data['id']);
  484. Db::table('wa_users')->where('id', $data['user_id'])->increment('accumulate_thirteen', $goodsData->balance);
  485. }
  486. if (!empty($goodsData->usd_quota)) {
  487. StreamBusiness::addStream($data['user_id'], $goodsData->usd_quota, streamType36, moldType14, moldTypefild14, $data['id']);
  488. Db::table('wa_users')->where('id', $data['user_id'])->increment('accumulate_fourteen', $goodsData->usd_quota);
  489. }
  490. if (!empty($goodsData->ranking)) {
  491. $cardlist = Db::table('wa_user_social_cark')->where('user_id', $data['user_id'])->first();
  492. if (!empty($cardlist)) {
  493. if ($cardlist->ranking > $goodsData->ranking) {
  494. Db::table('wa_user_social_cark')->where('id', $cardlist->id)->decrement('ranking', $goodsData->ranking);
  495. Db::table('wa_my_goods')->where('id', $myGoodsId)->update([
  496. 'ranking' => $goodsData->ranking,
  497. ]);
  498. $new_ranking = bcsub($cardlist->ranking, $goodsData->ranking);
  499. Db::table('wa_users')->where('id', $data['user_id'])->increment('increase_ranking', $goodsData->ranking);
  500. } else {
  501. $new_ranking = $cardlist->ranking;
  502. }
  503. Db::table('wa_users')->where('id', $data['user_id'])->update(['new_ranking' => $new_ranking]);
  504. }
  505. }
  506. /** 分佣 */
  507. $system = Db::table('wa_system')->first();
  508. if (!empty($userlist->pid) && !empty($system->rebate)) {
  509. StreamBusiness::addStream($userlist->pid, bcmul($goodsData->pay_price, bcdiv($system->rebate, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  510. }
  511. if (!empty($userlist->ppid) && !empty($system->rebate_one)) {
  512. StreamBusiness::addStream($userlist->ppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_one, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  513. }
  514. if (!empty($userlist->toppid) && !empty($system->rebate_two)) {
  515. StreamBusiness::addStream($userlist->toppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_two, 100, 2), 2), streamType10, moldType8, moldTypefild8, $data['id']);
  516. }
  517. } elseif ($goodsData->type == 5) {
  518. $futureDay = futureDay($goodsData->day);
  519. $myGoodsId_two = Db::table('wa_my_goods')->insertGetId([
  520. 'user_id' => $data['user_id'],
  521. 'goods_id' => $goodsData->id,
  522. 'money' => $data['money'],
  523. 'num' => $data['num'],
  524. 'on' => date('YmdHis') . mt_rand(1000, 9999),
  525. 'type' => $goodsData->type,
  526. 'pay_id' => $data['id'],
  527. 'bonus' => $goodsData->bonus,
  528. 'balance' => $goodsData->balance,
  529. 'usd_quota' => $goodsData->usd_quota,
  530. 'refund_amount' => $data['money'],
  531. 'name' => Arr::get($data, 'name', null),
  532. 'mobile' => Arr::get($data, 'mobile', null),
  533. 'number' => Arr::get($data, 'number', null),
  534. 'address' => Arr::get($data, 'address', null),
  535. 'expiretime' => strtotime($futureDay),
  536. 'expiredate' => $futureDay,
  537. 'created_at' => $thisDay,
  538. 'updated_at' => $thisDay,
  539. ]);
  540. if (!empty($goodsData->bonus)) {
  541. Db::table('wa_cron_task')->insert([
  542. 'user_id' => $data['user_id'],
  543. 'goods_id' => $goodsData->id,
  544. 'order_id' => $data['id'],
  545. 'money' => $data['money'],
  546. 'bonus' => $goodsData->bonus,
  547. 'balance' => $goodsData->balance,
  548. 'rebate' => $goodsData->rebate,
  549. 'rebate_one' => $goodsData->rebate_one,
  550. 'rebate_two' => $goodsData->rebate_two,
  551. 'goods_type' => $goodsData->type,
  552. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:10:00'),
  553. 'dividend_time' => strtotime($futureDay),
  554. 'created_at' => $thisDay,
  555. 'updated_at' => $thisDay,
  556. 'my_good_id' => $myGoodsId_two,
  557. 'event_time' => 0,
  558. 'is_activity' => 0,
  559. ]);
  560. StreamBusiness::addStream($data['user_id'], $goodsData->bonus, streamType43, moldType15, moldTypefild15, $data['id']);
  561. }
  562. if (!empty($goodsData->balance)) {
  563. StreamBusiness::addStream($data['user_id'], $goodsData->balance, streamType43, moldType3, moldTypefild3, $data['id']);
  564. }
  565. if (!empty($goodsData->bonus)) {
  566. Db::table('wa_cron_task')->insert([
  567. 'user_id' => $data['user_id'],
  568. 'goods_id' => $goodsData->id,
  569. 'order_id' => $data['id'],
  570. 'money' => $data['money'],
  571. 'bonus' => $goodsData->bonus,
  572. 'balance' => $goodsData->balance,
  573. 'rebate' => $goodsData->rebate,
  574. 'rebate_one' => $goodsData->rebate_one,
  575. 'rebate_two' => $goodsData->rebate_two,
  576. 'goods_type' => $goodsData->type,
  577. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:10:00'),
  578. 'dividend_time' => strtotime($futureDay),
  579. 'created_at' => $thisDay,
  580. 'updated_at' => $thisDay,
  581. 'my_good_id' => $myGoodsId,
  582. 'event_time' => 0,
  583. 'is_activity' => 0,
  584. ]);
  585. StreamBusiness::addStream($data['user_id'], $goodsData->bonus, streamType43, moldType15, moldTypefild15, $data['id']);
  586. }
  587. if (!empty($goodsData->balance)) {
  588. StreamBusiness::addStream($data['user_id'], $goodsData->balance, streamType43, moldType3, moldTypefild3, $data['id']);
  589. }
  590. Db::table('wa_users')->where('id', $data['user_id'])->update(['mailing_date' => strtotime(futureDay($goodsData->mailing_date))]);
  591. /** 分佣 */
  592. $system = Db::table('wa_system')->first();
  593. if (!empty($userlist->pid) && !empty($system->rebate)) {
  594. StreamBusiness::addStream($userlist->pid, bcmul($goodsData->pay_price, bcdiv($system->rebate, 100, 2), 2), streamType42, moldType16, moldTypefild16, $data['id']);
  595. }
  596. if (!empty($userlist->ppid) && !empty($system->rebate_one)) {
  597. StreamBusiness::addStream($userlist->ppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_one, 100, 2), 2), streamType42, moldType16, moldTypefild16, $data['id']);
  598. }
  599. if (!empty($userlist->toppid) && !empty($system->rebate_two)) {
  600. StreamBusiness::addStream($userlist->toppid, bcmul($goodsData->pay_price, bcdiv($system->rebate_two, 100, 2), 2), streamType42, moldType16, moldTypefild16, $data['id']);
  601. }
  602. } elseif ($goodsData->type == 6) {
  603. StreamBusiness::addStream($data['user_id'], $goodsData->pay_price, streamType45, moldType17, moldTypefild17, $data['id']);
  604. } elseif ($goodsData->type == 7) {
  605. StreamBusiness::addStream($data['user_id'], $goodsData->pay_price, streamType45, moldType17, moldTypefild17, $data['id']);
  606. } elseif ($goodsData->type == 8) {
  607. Db::table('wa_users')->where('id', $data['user_id'])->update(['is_protocol' => 1, 'protocol_time' => date('Y-m-d H:i:s')]);
  608. StreamBusiness::addStream($data['user_id'], $goodsData->pay_price, streamType45, moldType17, moldTypefild17, $data['id']);
  609. } elseif ($goodsData->type == 9) {
  610. StreamBusiness::addStream($data['user_id'], $goodsData->pay_price, streamType45, moldType17, moldTypefild17, $data['id']);
  611. } elseif ($goodsData->type == 10) {
  612. StreamBusiness::addStream($data['user_id'], $goodsData->pay_price, streamType45, moldType17, moldTypefild17, $data['id']);
  613. } elseif ($goodsData->type == 11) {
  614. StreamBusiness::addStream($data['user_id'], $goodsData->pay_price, streamType45, moldType17, moldTypefild17, $data['id']);
  615. } elseif ($goodsData->type == 12) {
  616. StreamBusiness::addStream($data['user_id'], $goodsData->pay_price, streamType45, moldType17, moldTypefild17, $data['id']);
  617. Db::table('wa_users')->where('id', $data['user_id'])->update(['pin_code' => mt_rand(100000, 999999), 'updated_at' => date('Y-m-d H:i:s')]);
  618. } elseif ($goodsData->type == 13) {
  619. StreamBusiness::addStream($data['user_id'], $goodsData->pay_price, streamType45, moldType17, moldTypefild17, $data['id']);
  620. } elseif ($goodsData->type == 14) {
  621. StreamBusiness::addStream($data['user_id'], $goodsData->pay_price, streamType45, moldType17, moldTypefild17, $data['id']);
  622. Db::table('wa_withdraw')
  623. ->where('user_id', $data['user_id'])
  624. ->whereIn('type', [10, 16, 17, 18])
  625. ->update(['new_state' => 1, 'updated_at' => date('Y-m-d H:i:s', time())]);
  626. } elseif ($goodsData->type == 15) {
  627. Db::table('wa_withdraw')
  628. ->where('user_id', $data['user_id'])
  629. ->where('new_state', 1)
  630. ->whereIn('type', [10, 16, 17, 18])
  631. ->update(['new_state' => 2, 'updated_at' => date('Y-m-d H:i:s', time())]);
  632. StreamBusiness::addStream($data['user_id'], $goodsData->pay_price, streamType45, moldType19, moldTypefild19, $data['id']);
  633. $bankCard = Db::table('wa_bank_card')->where('uid', $data['user_id'])->first();
  634. if (empty($bankCard)) {
  635. $affiliated_bank = '';
  636. $account_holder = '';
  637. $card_number = '';
  638. } else {
  639. $affiliated_bank = $bankCard->affiliated_bank;
  640. $account_holder = $bankCard->account_holder;
  641. $card_number = $bankCard->card_number;
  642. }
  643. if(!empty($userlist->money_ten)){
  644. $withdrawId = Db::table('wa_withdraw')->insertGetId([
  645. 'order_no' => date('YmdHis') . mt_rand(10000, 99999),
  646. 'user_id' => $data['user_id'],
  647. 'money' => $userlist->money_ten,
  648. 'type' => 10,
  649. 'affiliated_bank' => $affiliated_bank,
  650. 'account_holder' => $account_holder,
  651. 'card_number' => $card_number,
  652. 'img' => '',
  653. 'created_at' => date('Y-m-d H:i:s'),
  654. 'updated_at' => date('Y-m-d H:i:s'),
  655. 'status' => 3,
  656. 'new_state' => 2
  657. ]);
  658. StreamBusiness::delStream($data['user_id'], $userlist->money_ten, streamType4,moldType10, moldTypefild10, $withdrawId);
  659. }
  660. if(!empty($userlist->money_sixteen)){
  661. $withdrawIdtwo = Db::table('wa_withdraw')->insertGetId([
  662. 'order_no' => date('YmdHis') . mt_rand(10000, 99999),
  663. 'user_id' => $data['user_id'],
  664. 'money' => $userlist->money_sixteen,
  665. 'type' => 16,
  666. 'affiliated_bank' => $affiliated_bank,
  667. 'account_holder' => $account_holder,
  668. 'card_number' => $card_number,
  669. 'img' => '',
  670. 'created_at' => date('Y-m-d H:i:s'),
  671. 'updated_at' => date('Y-m-d H:i:s'),
  672. 'status' => 3,
  673. 'new_state' => 2
  674. ]);
  675. StreamBusiness::delStream($data['user_id'], $userlist->money_sixteen, streamType4,moldType16, moldTypefild16, $withdrawIdtwo);
  676. }
  677. if(!empty($userlist->money_seventeen)){
  678. $withdrawIdthree = Db::table('wa_withdraw')->insertGetId([
  679. 'order_no' => date('YmdHis') . mt_rand(10000, 99999),
  680. 'user_id' => $data['user_id'],
  681. 'money' => $userlist->money_seventeen,
  682. 'type' => 17,
  683. 'affiliated_bank' => $affiliated_bank,
  684. 'account_holder' => $account_holder,
  685. 'card_number' => $card_number,
  686. 'img' => '',
  687. 'created_at' => date('Y-m-d H:i:s'),
  688. 'updated_at' => date('Y-m-d H:i:s'),
  689. 'status' => 3,
  690. 'new_state' => 2
  691. ]);
  692. StreamBusiness::delStream($data['user_id'], $userlist->money_seventeen, streamType4,moldType17, moldTypefild17, $withdrawIdthree);
  693. }
  694. }elseif ($goodsData->type == 16) {
  695. if (!empty($goodsData->bonus)) {
  696. Db::table('wa_cron_task')->insert([
  697. 'user_id' => $data['user_id'],
  698. 'goods_id' => $goodsData->id,
  699. 'order_id' => $data['id'],
  700. 'money' => $data['money'],
  701. 'bonus' => $goodsData->bonus,
  702. 'rebate' => $goodsData->rebate,
  703. 'rebate_one' => $goodsData->rebate_one,
  704. 'rebate_two' => $goodsData->rebate_two,
  705. 'goods_type' => $goodsData->type,
  706. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:10:00'),
  707. 'dividend_time' => strtotime($futureDay),
  708. 'created_at' => $thisDay,
  709. 'updated_at' => $thisDay,
  710. 'my_good_id' => $myGoodsId,
  711. ]);
  712. StreamBusiness::addStream($data['user_id'], $goodsData->bonus, streamType51, moldType20, moldTypefild20, $data['id']);
  713. if (!empty($userlist->pid) && !empty($goodsData->rebate)) {
  714. StreamBusiness::addStream($userlist->pid, $goodsData->rebate, streamType51, moldType21, moldTypefild21, $data['id']);
  715. }
  716. if (!empty($userlist->ppid) && !empty($goodsData->rebate_one)) {
  717. StreamBusiness::addStream($userlist->ppid, $goodsData->rebate_one, streamType51, moldType21, moldTypefild21, $data['id']);
  718. }
  719. if (!empty($userlist->toppid) && !empty($goodsData->rebate_two)) {
  720. StreamBusiness::addStream($userlist->toppid, $goodsData->rebate_two, streamType51, moldType21, moldTypefild21, $data['id']);
  721. }
  722. }
  723. }elseif ($goodsData->type == 17) {
  724. if (!empty($goodsData->bonus)) {
  725. Db::table('wa_cron_task')->insert([
  726. 'user_id' => $data['user_id'],
  727. 'goods_id' => $goodsData->id,
  728. 'order_id' => $data['id'],
  729. 'money' => $data['money'],
  730. 'bonus' => $goodsData->bonus,
  731. 'rebate' => $goodsData->rebate,
  732. 'rebate_one' => $goodsData->rebate_one,
  733. 'rebate_two' => $goodsData->rebate_two,
  734. 'goods_type' => $goodsData->type,
  735. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:10:00'),
  736. 'dividend_time' => strtotime($futureDay),
  737. 'created_at' => $thisDay,
  738. 'updated_at' => $thisDay,
  739. 'my_good_id' => $myGoodsId,
  740. ]);
  741. StreamBusiness::addStream($data['user_id'], $goodsData->bonus, streamType52, moldType24, moldTypefild24, $data['id']);
  742. }
  743. if (!empty($goodsData->balance)) {
  744. StreamBusiness::addStream($data['user_id'], $goodsData->balance, streamType52, moldType25, moldTypefild25, $data['id']);
  745. }
  746. }elseif ($goodsData->type == 18) {
  747. }elseif ($goodsData->type == 19) {
  748. }elseif ($goodsData->type == 20) {
  749. }elseif ($goodsData->type == 21) {
  750. Db::table('wa_withdraw')
  751. ->where('user_id', $data['user_id'])
  752. ->where('type',22)
  753. ->where('status','<',3)
  754. ->update(['status' => 3, 'updated_at' => date('Y-m-d H:i:s', time())]);
  755. }elseif ($goodsData->type == 22) {
  756. Db::table('wa_withdraw')
  757. ->where('user_id', $data['user_id'])
  758. ->where('type',10)
  759. ->where('status','<',3)
  760. ->update(['status' => 3, 'updated_at' => date('Y-m-d H:i:s', time())]);
  761. }elseif ($goodsData->type == 23) {
  762. Db::table('wa_withdraw')
  763. ->where('user_id', $data['user_id'])
  764. ->where('type',23)
  765. ->where('status','<',3)
  766. ->update(['status' => 3, 'updated_at' => date('Y-m-d H:i:s', time())]);
  767. }
  768. /** 新增消费数据 */
  769. Db::table('wa_users')->where('id', $data['user_id'])->increment('invest_money', $data['money']);
  770. Db::table('wa_goods')->where('id', $goodsData->id)->decrement('num', $data['num']);
  771. } catch (\Throwable $exception) {
  772. throw new \Exception($exception->getMessage());
  773. }
  774. }
  775. }