TestCommand.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Exports\Dwbs\ShopOrderExport;
  4. use App\Exports\Dwbs\UserOrderGoodExport;
  5. use App\Jobs\Dwbs\ImportOrderJob;
  6. use App\Repositories\Enums\Dwbs\DayTypeEnum;
  7. use App\Repositories\Enums\Dwbs\StatisticalResourceTypeEnum;
  8. use App\Repositories\Enums\ModelStatusEnum;
  9. use App\Repositories\Enums\ResponseCodeEnum;
  10. use App\Repositories\Models\Base\User;
  11. use App\Repositories\Models\Dwbs\Good;
  12. use App\Repositories\Models\Dwbs\Order;
  13. use App\Repositories\Models\Dwbs\OrderGood;
  14. use App\Repositories\Models\Dwbs\Ranking;
  15. use App\Repositories\Models\Dwbs\ShopGood;
  16. use App\Repositories\Models\Dwbs\ShopOrder;
  17. use App\Repositories\Models\Dwbs\ShopOrderGood;
  18. use App\Repositories\Models\Dwbs\StatisticalResource;
  19. use App\Repositories\Models\Dwbs\UserJifen;
  20. use App\Repositories\Models\Dwbs\UserXuefen;
  21. use App\Repositories\Models\Dwbs\Zhengshu;
  22. use App\Services\Dwbs\WechatTemplateMessageService;
  23. use App\Support\Sdk\Express\Express;
  24. use Carbon\Carbon;
  25. use EasyWeChat\Factory;
  26. use Illuminate\Console\Command;
  27. use Illuminate\Support\Facades\Artisan;
  28. use Illuminate\Support\Facades\Cache;
  29. use Illuminate\Support\Facades\Crypt;
  30. use Illuminate\Support\Facades\DB;
  31. use Illuminate\Support\Facades\Http;
  32. use Illuminate\Support\Facades\Redis;
  33. use Illuminate\Support\Facades\Storage;
  34. use Illuminate\Support\Str;
  35. use Intervention\Image\Facades\Image;
  36. use Overtrue\EasySms\PhoneNumber;
  37. use Vinkla\Hashids\Facades\Hashids;
  38. /**
  39. * Class PresenterCommand
  40. * @package Prettus\Repository\Generators\Commands
  41. * @author Anderson Andrade <contato@andersonandra.de>
  42. */
  43. class TestCommand extends Command
  44. {
  45. /**
  46. * The name of command.
  47. *
  48. * @var string
  49. */
  50. protected $name = 'mead:test';
  51. /**
  52. * The description of command.
  53. *
  54. * @var string
  55. */
  56. protected $description = 'test';
  57. /**
  58. * The type of class being generated.
  59. *
  60. * @var string
  61. */
  62. protected $type = 'permission';
  63. /**
  64. * Execute the command.
  65. *
  66. * @return void
  67. * @see fire()
  68. */
  69. public function handle()
  70. {
  71. $this->exportShopOrder();
  72. dd(1);
  73. // $day = "2024-10-27";
  74. // $firstDayOfWeek = Carbon::now()->startOfMonth();
  75. // dd($firstDayOfWeek);
  76. //// dd($firstDayOfWeek);
  77. // if (Carbon::parse($day)->isSameDay($firstDayOfWeek)) {
  78. // $startTimeTxt = Carbon::parse($day)->startOfWeek()->format('Y年m月d日 H:i');
  79. // $endTimeTxt = Carbon::parse($day)->endOfWeek()->format('Y年m月d日 H:i');
  80. // $timeTxt = "{$startTimeTxt}-{$endTimeTxt}";
  81. // dd($timeTxt);
  82. // }
  83. // $bg = base_path('Data/huojian_bg.png');
  84. // $image = Image::make($bg)->resize(375, 646);
  85. //
  86. // $nickname = '你好你好你好...';
  87. // self::addText($image, $nickname, 375 / 2, 210, 40, 'F00');
  88. // $day = date('Y-m-d');
  89. //
  90. // self::addText($image, Carbon::parse($day)->format('Y年m月d日'), 375 / 2, 458, 16, '3d3d3d');
  91. // $dir = "huojianImg/" . $day;
  92. // $filename = Str::random() . '.png';
  93. // $filename = 'mead.png';
  94. //
  95. //
  96. // Storage::disk('public')->put("{$dir}/{$filename}.txt", 1);
  97. // $path = Storage::disk('public')->path("{$dir}/{$filename}");
  98. // $image->save($path);
  99. //
  100. // Storage::disk('public')->delete("{$dir}/{$filename}.txt");
  101. // $this->testOrderData();
  102. // $this->makeUserOrder(4, 1);
  103. // User::refreshUserTag(4);
  104. // $this->makeUserOrder(4, 1);
  105. // WechatTemplateMessageService::sendAddXuefen(4, 1);
  106. // $this->areaToBase();
  107. // ShopOrder::query()->truncate();
  108. // ShopGood::query()->update(['nums' => 3, 'duihuan_nums' => 0]);
  109. // ShopOrderGood::query()->truncate();
  110. //
  111. // Cache::flush();
  112. // $goods = ShopGood::query()->get();
  113. // foreach ($goods as $good) {
  114. // ShopGood::updateKuCun($good->id, $good->nums);
  115. // }
  116. //
  117. // $a = Cache::increment("mead:nums");
  118. // Cache::decrement("mead:nums", $a);
  119. // ShopGood::addGoodNums(1, 1, 2);
  120. // $url = '/admin/base/auth/login';
  121. // dd(strpos($url, "/admin/") == 0);
  122. $this->export('2024-10-01', '2024-12-01', 1);
  123. $days = Carbon::now()->diffInDays(Carbon::parse("2024-12-30"));
  124. for ($i = 0; $i < $days; $i++) {
  125. $day = Carbon::now()->subDays($days)->clone()->addDays($i)->toDateString();
  126. $this->line("数据:{$day}");
  127. Artisan::call("statistical:user {$day}");
  128. }
  129. $this->line('ok');
  130. }
  131. public function export($start_day, $end_day, $limit = 1000)
  132. {
  133. $users = Ranking::query()->where('day_type', DayTypeEnum::day)->select(['user_id', DB::raw("sum(day_xuefen) as dxf")])->groupBy('user_id')->orderByDesc('dxf')->limit(10)->get();
  134. foreach ($users as $user) {
  135. $gs = OrderGood::query()->where('user_id', $user['user_id'])->select(['user_id', 'good_id', DB::raw('count(nums) as good_nums')])->groupBy('good_id')->pluck('good_nums', 'good_id');
  136. }
  137. }
  138. public function areaToBase()
  139. {
  140. $provinces = json_decode(file_get_contents(base_path('app/Support/Sdk/Address/province.json')), true);
  141. $citys = json_decode(file_get_contents(base_path('app/Support/Sdk/Address/city.json')), true);
  142. $areas = json_decode(file_get_contents(base_path('app/Support/Sdk/Address/area.json')), true);
  143. $sheng = [];
  144. $shi = [];
  145. $qu = [];
  146. foreach ($provinces as $province) {
  147. $sheng[$province['value'] . '0000'] = [
  148. 'name' => $province['label'],
  149. 'pid' => 0,
  150. 'zipcode' => $province['value'] . '0000',
  151. ];
  152. }
  153. file_put_contents(base_path('app/Support/Sdk/Address/province_1.json'), json_encode($sheng, JSON_UNESCAPED_UNICODE));
  154. foreach ($citys as $s) {
  155. foreach ($s as $ss) {
  156. $sc = substr($ss['value'], 0, 2);
  157. $shi[$ss['value'] . '00'] = [
  158. 'name' => $ss['label'],
  159. 'pid' => $sc . '0000',
  160. 'zipcode' => $ss['value'] . '00',
  161. ];
  162. }
  163. }
  164. file_put_contents(base_path('app/Support/Sdk/Address/city_1.json'), json_encode($shi, JSON_UNESCAPED_UNICODE));
  165. foreach ($areas as $s) {
  166. foreach ($s as $ss) {
  167. foreach ($ss as $sss) {
  168. $sc = substr($sss['value'], 0, 4);
  169. $qu[$sss['value']] = [
  170. 'name' => $sss['label'],
  171. 'pid' => $sc . '00',
  172. 'zipcode' => $sss['value'],
  173. ];
  174. }
  175. }
  176. }
  177. file_put_contents(base_path('app/Support/Sdk/Address/area_1.json'), json_encode($qu, JSON_UNESCAPED_UNICODE));
  178. }
  179. public function makeUserOrder($user_id, $order_nums = 1)
  180. {
  181. $users = User::query()->where('id', $user_id)->get();
  182. $tx = 0;
  183. foreach ($users as $user) {
  184. for ($o = 1; $o <= $order_nums; $o++) {
  185. $txf = random_int(1, 3);
  186. $da = [];
  187. $goods = Good::query()->inRandomOrder()->limit($txf)->get();
  188. foreach ($goods as $good) {
  189. $num = random_int(1, 5);
  190. $da[] = [
  191. 'ProductGroupID' => 9,
  192. 'ProductGroupSKUID' => 9,
  193. 'ProductName' => "大卫博士罐装内裤(青春版)",
  194. 'ProductCode' => $good['name'],
  195. 'SKUCode' => "青春版",
  196. 'AttributesVales' => [],
  197. 'Qty' => $num,
  198. ];
  199. $tx += $num * $good['xuefen'];
  200. }
  201. $data = [
  202. 'Type' => 1,
  203. 'RetailID' => 134,
  204. 'Code' => Order::makeNo(),
  205. 'AuthorizationCode' => $user->code,
  206. 'Domain' => "http://hnsystemse.njjinhao.top/",
  207. 'data' => $da
  208. ];
  209. dispatch(new ImportOrderJob(json_encode($data, true)));
  210. }
  211. $this->line($tx);
  212. }
  213. }
  214. public function testOrderData()
  215. {
  216. //{"Type":1,"RetailID":134,"Code":"2024102947561000002","Domain":"http://hnsystemse.njjinhao.top/","data":[{"ProductGroupID":9,"ProductGroupSKUID":9,"ProductName":"大卫博士罐装内裤(青春版)","ProductCode":"青春版","SKUCode":"青春版","AttributesVales":[],"Qty":2}]}
  217. $data = [
  218. 'Type' => 1,
  219. 'RetailID' => 134,
  220. 'Code' => 2024102947561000002,
  221. 'AuthorizationCode' => 'M100001',
  222. 'Domain' => "http://hnsystemse.njjinhao.top/",
  223. 'data' => [
  224. [
  225. 'ProductGroupID' => 9,
  226. 'ProductGroupSKUID' => 9,
  227. 'ProductName' => "大卫博士罐装内裤(青春版)",
  228. 'ProductCode' => "青春版",
  229. 'SKUCode' => "青春版",
  230. 'AttributesVales' => [],
  231. 'Qty' => 2,
  232. ]
  233. ]
  234. ];
  235. dispatch(new ImportOrderJob(json_encode($data, true)));
  236. }
  237. public static function addText(&$bgImage, $text, $x, $y, $size, $color, $align = 'center', $valign = 'middle', $ziti = '')
  238. {
  239. if (!$ziti) $ziti = base_path('Data/ziti/ht.otf');
  240. // $y += ($size / 2);
  241. $bgImage->text($text, $x, $y, function ($font) use ($size, $color, $ziti, $align, $valign) {
  242. $font->file($ziti);
  243. $font->size($size);
  244. $font->color($color);
  245. $font->angle(0);
  246. $font->align($align);
  247. $font->valign($valign);
  248. });
  249. // return $bgImage;
  250. }
  251. public function exportShopOrder()
  252. {
  253. $file_name = time() . '.xlsx';
  254. $ids = [2];
  255. // (new ShopOrderExport($ids))->store($file_name);
  256. (new UserOrderGoodExport([
  257. 'limit' => 1,
  258. 'start_day'=> 0,
  259. 'end_day'=> 0,
  260. ]))->store($file_name);
  261. }
  262. }