-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b2374b
commit 67a7b1f
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
app/console/modules/Order/controllers/ItemController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
/** | ||
* FecShop file. | ||
* | ||
* @link http://www.fecshop.com/ | ||
* @copyright Copyright (c) 2016 FecShop Software LLC | ||
* @license http://www.fecshop.com/license/ | ||
*/ | ||
|
||
namespace fecshop\app\console\modules\Order\controllers; | ||
|
||
use Yii; | ||
use yii\console\Controller; | ||
|
||
/** | ||
* @author Terry Zhao <2358269014@qq.com> | ||
* @since 1.0 | ||
*/ | ||
class ItemController extends Controller | ||
{ | ||
public $pageNum = 10; | ||
|
||
public function actionCount() | ||
{ | ||
$data = $this->getOrderData(); | ||
if (isset($data['count']) && $data['count']) { | ||
echo $data['count']; | ||
} | ||
|
||
return; | ||
} | ||
|
||
public function actionPagenum() | ||
{ | ||
$data = $this->getOrderData(); | ||
if (isset($data['count']) && $data['count']) { | ||
echo ceil($data['count'] / $this->pageNum); | ||
} | ||
|
||
return; | ||
} | ||
|
||
public function actionComputesellercount($pageNum) | ||
{ | ||
Yii::$service->product->updateAllScoreToZero(); | ||
$orderData = $this->getOrderData($pageNum); | ||
$order_ids = []; | ||
if (isset($orderData['coll']) && is_array($orderData['coll'])) { | ||
foreach ($orderData['coll'] as $one) { | ||
$order_ids[] = $one['order_id']; | ||
} | ||
} | ||
if (empty($order_ids)) { | ||
return false; | ||
} | ||
$productSaleArr = []; | ||
$itemData = $this->getOrderItemsData($order_ids); | ||
if (isset($itemData['coll']) && is_array($itemData['coll']) ) { | ||
foreach ($itemData['coll'] as $item) { | ||
$sku = $item['sku']; | ||
$qty = $item['qty']; | ||
|
||
if (isset($productSaleArr[$sku])) { | ||
$productSaleArr[$sku] += (int)$qty; | ||
} else { | ||
$productSaleArr[$sku] = (int)$qty; | ||
} | ||
} | ||
} | ||
echo "Print Sku And Sales Qty List: \n"; | ||
var_dump($productSaleArr); | ||
foreach ($productSaleArr as $sku => $qty) { | ||
$product = Yii::$service->product->getBySku((string)$sku, false); | ||
if ($product['sku']) { | ||
$product['score'] += (int)$qty; | ||
$product->save(); | ||
//echo $sku."=>".$qty."\n"; | ||
} | ||
} | ||
|
||
return ture; | ||
} | ||
|
||
|
||
public function getOrderItemsData($order_ids){ | ||
if (!is_array($order_ids) || empty($order_ids)) { | ||
return; | ||
} | ||
$filter = [ | ||
'where' => [ | ||
['in', 'order_id', $order_ids] | ||
], | ||
]; | ||
|
||
return Yii::$service->order->item->coll($filter); | ||
} | ||
|
||
public function getOrderData($pageNum = 0){ | ||
$paymentOrderStatus = Yii::$service->order->getOrderPaymentedStatusArr(); | ||
$orderProductSaleInMonths = Yii::$service->order->orderProductSaleInMonths; | ||
$beginDate = strtotime('-'.$orderProductSaleInMonths.' months'); | ||
$filter = [ | ||
'where' => [ | ||
['order_status' => $paymentOrderStatus], | ||
['>', 'created_at', $beginDate] | ||
], | ||
]; | ||
if ($pageNum) { | ||
$filter['numPerPage'] = $this->pageNum; | ||
$filter['pageNum'] = $pageNum; | ||
} | ||
|
||
return Yii::$service->order->coll($filter); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
Cur_Dir=$(cd `dirname $0`; pwd) | ||
# get product all count. | ||
count=`$Cur_Dir/../../../../../yii order/item/count` | ||
pagenum=`$Cur_Dir/../../../../../yii order/item/pagenum` | ||
|
||
echo "There are $count order products to process" | ||
echo "There are $pagenum pages to process" | ||
echo "##############ALL BEGINING###############"; | ||
for (( i=1; i<=$pagenum; i++ )) | ||
do | ||
$Cur_Dir/../../../../../yii order/item/computesellercount $i | ||
echo "Page $i done" | ||
done | ||
|
||
echo "##############ALL COMPLETE###############"; |