TestCommand.php 9.8 KB

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