{"id":375,"date":"2021-12-26T20:46:09","date_gmt":"2021-12-26T12:46:09","guid":{"rendered":"http:\/\/blog.yuekegu.com\/?p=375"},"modified":"2021-12-26T20:46:09","modified_gmt":"2021-12-26T12:46:09","slug":"yii2-0%e5%ae%9e%e7%8e%b0%e7%9a%84%e6%89%b9%e9%87%8f%e6%9b%b4%e6%96%b0%e5%8f%8a%e6%89%b9%e9%87%8f%e6%8f%92%e5%85%a5%e5%8a%9f%e8%83%bd%e7%a4%ba%e4%be%8b","status":"publish","type":"post","link":"https:\/\/book.yuekegu.com\/index.php\/2021\/12\/26\/yii2-0%e5%ae%9e%e7%8e%b0%e7%9a%84%e6%89%b9%e9%87%8f%e6%9b%b4%e6%96%b0%e5%8f%8a%e6%89%b9%e9%87%8f%e6%8f%92%e5%85%a5%e5%8a%9f%e8%83%bd%e7%a4%ba%e4%be%8b\/","title":{"rendered":"Yii2.0\u5b9e\u73b0\u7684\u6279\u91cf\u66f4\u65b0\u53ca\u6279\u91cf\u63d2\u5165\u529f\u80fd\u793a\u4f8b"},"content":{"rendered":"\n<p>\u672c\u6587\u5b9e\u4f8b\u8bb2\u8ff0\u4e86Yii2.0\u5b9e\u73b0\u7684\u6279\u91cf\u66f4\u65b0\u53ca\u6279\u91cf\u63d2\u5165\u529f\u80fd\u3002\u5206\u4eab\u7ed9\u5927\u5bb6\u4f9b\u5927\u5bb6\u53c2\u8003\uff0c\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p><strong>\u6279\u91cf\u66f4\u65b0<\/strong><\/p>\n\n\n\n<p>\u65b9\u6cd51<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n* \u6279\u91cf\u66f4\u65b0\u5faa\u73af\u5468\u671f\n* @param array $condition\n* $condition = ['advertise_id' => '','status' => '', 'weekdays'=>[1,2,3]] \u67e5\u8be2\u6761\u4ef6\n* $params = ['status' => '']\n* @param $params\n* @return bool\n*\/\npublic function batchUpdateAdSchedule($condition = [], $params)\n{\n  if (count($condition) == 0 || !is_array($condition) || count($params) == 0) {\n    return false;\n  }\n  $conditions = ' 1 = 1 ';\n  $bind = [];\n  if (array_key_exists('advertise_id', $condition) &amp;&amp; !empty($condition['advertise_id'])) {\n    $conditions .= ' AND `advertise_id` = :advertiseId';\n    $bind['advertiseId'] = $condition['advertise_id'];\n  }\n  if (array_key_exists('status', $condition) &amp;&amp; !empty($condition['status'])) {\n    $conditions .= ' AND `status` = :status';\n    $bind['status'] = $condition['status'];\n  }\n  $result = AdvertiseSchedule::updateAll($params, $conditions, $bind);\n  return $result > 0 ? true : false;\n}\n\n<\/code><\/pre>\n\n\n\n<p> \u65b9\u6cd52 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n* \u6279\u91cf\u66f4\u65b0\u5546\u54c1\u9500\u91cf\n* @param $params\n* @return bool|int\n* @throws \\yii\\db\\Exception\n*\/\npublic function batchUpdateSalesNum($params)\n{\n  if (count($params) == 0 || !is_array($params)) {\n    return false;\n  }\n  $sql = '';\n  foreach ($params as $key => $value) {\n    $sql .= 'UPDATE `morefun`.`mbb_goods` SET `sale_num` = `sale_num` -' . $value['amount'] . ' WHERE `id` =' . $value['goods_id'] . ';';\n  }\n  $result = Yii::$app->db->createCommand($sql)->execute();\n  return $result == 1 ? true : false;\n}\n\n<\/code><\/pre>\n\n\n\n<p><strong>\u6279\u91cf\u63d2\u5165<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n* \u6279\u91cf\u63d2\u5165\n* @param $params\n* @return int\n* @throws \\yii\\db\\Exception\n*\/\npublic function batchAddShopClassConn($params)\n{\n  $connection = Yii::$app->db;\n  $queryBuilder = $connection->queryBuilder;\n  \/*$sql = $queryBuilder->batchInsert('user', ['name', 'age'], [\n    ['Tom', 30],\n    ['Jane', 20],\n    ['Linda', 25],\n  ]);*\/\n  $sql = $queryBuilder->batchInsert(shopClassConn::tableName(),\n    ['shop_id', 'class_id'], $params);\n  return $connection->createCommand($sql)->execute();\n}\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5b9e\u4f8b\u8bb2\u8ff0\u4e86Yii2.0\u5b9e\u73b0\u7684\u6279\u91cf\u66f4\u65b0\u53ca\u6279\u91cf\u63d2\u5165\u529f\u80fd\u3002\u5206\u4eab\u7ed9\u5927\u5bb6\u4f9b\u5927\u5bb6\u53c2\u8003\uff0c\u5177\u4f53\u5982\u4e0b\uff1a \u6279\u91cf\u66f4\u65b0 \u65b9\u6cd51 \u65b9\u6cd52 \u6279\u91cf\u63d2\u5165<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-375","post","type-post","status-publish","format-standard","hentry","category-yii2"],"_links":{"self":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/comments?post=375"}],"version-history":[{"count":0,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/375\/revisions"}],"wp:attachment":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/media?parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/categories?post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/tags?post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}