123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- <?php
- namespace App\Console\Commands;
- use App\Exports\Dwbs\ShopOrderExport;
- use App\Exports\Dwbs\UserOrderGoodExport;
- use App\Jobs\Dwbs\ImportOrderJob;
- use App\Repositories\Enums\Dwbs\DayTypeEnum;
- use App\Repositories\Enums\Dwbs\StatisticalResourceTypeEnum;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Enums\ResponseCodeEnum;
- use App\Repositories\Models\Base\User;
- use App\Repositories\Models\Dwbs\Good;
- use App\Repositories\Models\Dwbs\Order;
- use App\Repositories\Models\Dwbs\OrderGood;
- use App\Repositories\Models\Dwbs\Ranking;
- use App\Repositories\Models\Dwbs\ShopGood;
- use App\Repositories\Models\Dwbs\ShopOrder;
- use App\Repositories\Models\Dwbs\ShopOrderGood;
- use App\Repositories\Models\Dwbs\StatisticalResource;
- use App\Repositories\Models\Dwbs\UserJifen;
- use App\Repositories\Models\Dwbs\UserXuefen;
- use App\Repositories\Models\Dwbs\Zhengshu;
- use App\Services\Dwbs\WechatTemplateMessageService;
- use App\Support\Sdk\Express\Express;
- use Carbon\Carbon;
- use EasyWeChat\Factory;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Artisan;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\Crypt;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Http;
- use Illuminate\Support\Facades\Redis;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Support\Str;
- use Intervention\Image\Facades\Image;
- use Overtrue\EasySms\PhoneNumber;
- use Vinkla\Hashids\Facades\Hashids;
- /**
- * Class PresenterCommand
- * @package Prettus\Repository\Generators\Commands
- * @author Anderson Andrade <contato@andersonandra.de>
- */
- class TestCommand extends Command
- {
- /**
- * The name of command.
- *
- * @var string
- */
- protected $name = 'mead:test';
- /**
- * The description of command.
- *
- * @var string
- */
- protected $description = 'test';
- /**
- * The type of class being generated.
- *
- * @var string
- */
- protected $type = 'permission';
- /**
- * Execute the command.
- *
- * @return void
- * @see fire()
- */
- public function handle()
- {
- $this->exportShopOrder();
- dd(1);
- // $day = "2024-10-27";
- // $firstDayOfWeek = Carbon::now()->startOfMonth();
- // dd($firstDayOfWeek);
- //// dd($firstDayOfWeek);
- // if (Carbon::parse($day)->isSameDay($firstDayOfWeek)) {
- // $startTimeTxt = Carbon::parse($day)->startOfWeek()->format('Y年m月d日 H:i');
- // $endTimeTxt = Carbon::parse($day)->endOfWeek()->format('Y年m月d日 H:i');
- // $timeTxt = "{$startTimeTxt}-{$endTimeTxt}";
- // dd($timeTxt);
- // }
- // $bg = base_path('Data/huojian_bg.png');
- // $image = Image::make($bg)->resize(375, 646);
- //
- // $nickname = '你好你好你好...';
- // self::addText($image, $nickname, 375 / 2, 210, 40, 'F00');
- // $day = date('Y-m-d');
- //
- // self::addText($image, Carbon::parse($day)->format('Y年m月d日'), 375 / 2, 458, 16, '3d3d3d');
- // $dir = "huojianImg/" . $day;
- // $filename = Str::random() . '.png';
- // $filename = 'mead.png';
- //
- //
- // Storage::disk('public')->put("{$dir}/{$filename}.txt", 1);
- // $path = Storage::disk('public')->path("{$dir}/{$filename}");
- // $image->save($path);
- //
- // Storage::disk('public')->delete("{$dir}/{$filename}.txt");
- // $this->testOrderData();
- // $this->makeUserOrder(4, 1);
- // User::refreshUserTag(4);
- // $this->makeUserOrder(4, 1);
- // WechatTemplateMessageService::sendAddXuefen(4, 1);
- // $this->areaToBase();
- // ShopOrder::query()->truncate();
- // ShopGood::query()->update(['nums' => 3, 'duihuan_nums' => 0]);
- // ShopOrderGood::query()->truncate();
- //
- // Cache::flush();
- // $goods = ShopGood::query()->get();
- // foreach ($goods as $good) {
- // ShopGood::updateKuCun($good->id, $good->nums);
- // }
- //
- // $a = Cache::increment("mead:nums");
- // Cache::decrement("mead:nums", $a);
- // ShopGood::addGoodNums(1, 1, 2);
- // $url = '/admin/base/auth/login';
- // dd(strpos($url, "/admin/") == 0);
- $this->export('2024-10-01', '2024-12-01', 1);
- $days = Carbon::now()->diffInDays(Carbon::parse("2025-02-05"));
- for ($i = 0; $i <= $days; $i++) {
- $day = Carbon::now()->subDays($days)->clone()->addDays($i)->toDateString();
- $this->line("数据:{$day}");
- Artisan::call("statistical:user {$day}");
- }
- $this->line('ok');
- }
- public function export($start_day, $end_day, $limit = 1000)
- {
- $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();
- foreach ($users as $user) {
- $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');
- }
- }
- public function areaToBase()
- {
- $provinces = json_decode(file_get_contents(base_path('app/Support/Sdk/Address/province.json')), true);
- $citys = json_decode(file_get_contents(base_path('app/Support/Sdk/Address/city.json')), true);
- $areas = json_decode(file_get_contents(base_path('app/Support/Sdk/Address/area.json')), true);
- $sheng = [];
- $shi = [];
- $qu = [];
- foreach ($provinces as $province) {
- $sheng[$province['value'] . '0000'] = [
- 'name' => $province['label'],
- 'pid' => 0,
- 'zipcode' => $province['value'] . '0000',
- ];
- }
- file_put_contents(base_path('app/Support/Sdk/Address/province_1.json'), json_encode($sheng, JSON_UNESCAPED_UNICODE));
- foreach ($citys as $s) {
- foreach ($s as $ss) {
- $sc = substr($ss['value'], 0, 2);
- $shi[$ss['value'] . '00'] = [
- 'name' => $ss['label'],
- 'pid' => $sc . '0000',
- 'zipcode' => $ss['value'] . '00',
- ];
- }
- }
- file_put_contents(base_path('app/Support/Sdk/Address/city_1.json'), json_encode($shi, JSON_UNESCAPED_UNICODE));
- foreach ($areas as $s) {
- foreach ($s as $ss) {
- foreach ($ss as $sss) {
- $sc = substr($sss['value'], 0, 4);
- $qu[$sss['value']] = [
- 'name' => $sss['label'],
- 'pid' => $sc . '00',
- 'zipcode' => $sss['value'],
- ];
- }
- }
- }
- file_put_contents(base_path('app/Support/Sdk/Address/area_1.json'), json_encode($qu, JSON_UNESCAPED_UNICODE));
- }
- public function makeUserOrder($user_id, $order_nums = 1)
- {
- $users = User::query()->where('id', $user_id)->get();
- $tx = 0;
- foreach ($users as $user) {
- for ($o = 1; $o <= $order_nums; $o++) {
- $txf = random_int(1, 3);
- $da = [];
- $goods = Good::query()->inRandomOrder()->limit($txf)->get();
- foreach ($goods as $good) {
- $num = random_int(1, 5);
- $da[] = [
- 'ProductGroupID' => 9,
- 'ProductGroupSKUID' => 9,
- 'ProductName' => "大卫博士罐装内裤(青春版)",
- 'ProductCode' => $good['name'],
- 'SKUCode' => "青春版",
- 'AttributesVales' => [],
- 'Qty' => $num,
- ];
- $tx += $num * $good['xuefen'];
- }
- $data = [
- 'Type' => 1,
- 'RetailID' => 134,
- 'Code' => Order::makeNo(),
- 'AuthorizationCode' => $user->code,
- 'Domain' => "http://hnsystemse.njjinhao.top/",
- 'data' => $da
- ];
- dispatch(new ImportOrderJob(json_encode($data, true)));
- }
- $this->line($tx);
- }
- }
- public function testOrderData()
- {
- //{"Type":1,"RetailID":134,"Code":"2024102947561000002","Domain":"http://hnsystemse.njjinhao.top/","data":[{"ProductGroupID":9,"ProductGroupSKUID":9,"ProductName":"大卫博士罐装内裤(青春版)","ProductCode":"青春版","SKUCode":"青春版","AttributesVales":[],"Qty":2}]}
- $data = [
- 'Type' => 1,
- 'RetailID' => 134,
- 'Code' => 2024102947561000002,
- 'AuthorizationCode' => 'M100001',
- 'Domain' => "http://hnsystemse.njjinhao.top/",
- 'data' => [
- [
- 'ProductGroupID' => 9,
- 'ProductGroupSKUID' => 9,
- 'ProductName' => "大卫博士罐装内裤(青春版)",
- 'ProductCode' => "青春版",
- 'SKUCode' => "青春版",
- 'AttributesVales' => [],
- 'Qty' => 2,
- ]
- ]
- ];
- dispatch(new ImportOrderJob(json_encode($data, true)));
- }
- public static function addText(&$bgImage, $text, $x, $y, $size, $color, $align = 'center', $valign = 'middle', $ziti = '')
- {
- if (!$ziti) $ziti = base_path('Data/ziti/ht.otf');
- // $y += ($size / 2);
- $bgImage->text($text, $x, $y, function ($font) use ($size, $color, $ziti, $align, $valign) {
- $font->file($ziti);
- $font->size($size);
- $font->color($color);
- $font->angle(0);
- $font->align($align);
- $font->valign($valign);
- });
- // return $bgImage;
- }
- public function exportShopOrder()
- {
- $file_name = time() . '.xlsx';
- $ids = [2];
- // (new ShopOrderExport($ids))->store($file_name);
- (new UserOrderGoodExport([
- 'limit' => 1,
- 'start_day'=> 0,
- 'end_day'=> 0,
- ]))->store($file_name);
- }
- }
|